Skip to content

Commit

Permalink
some renamings, better docstrings, remove useless variable copies
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
marcelmbn committed Jan 28, 2025
1 parent 3354eac commit 379b6ab
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/mindlessgen/generator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ def single_molecule_step(
except RuntimeError as e:
if config.general.verbosity > 0:
print(f"Structure modification failed for cycle {cycle + 1}.")
if config.general.verbosity > 1:
print(e)
if config.general.verbosity > 1:
print(e)
return None

if config.general.postprocess:
Expand Down
4 changes: 2 additions & 2 deletions src/mindlessgen/prog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ def write_xyz(self, write_xyz: bool):
@property
def symmetrization(self):
"""
Get the structure_mod flag.
Get the symmetrization flag.
"""
return self._symmetrization

@symmetrization.setter
def symmetrization(self, symmetrization: bool):
"""
Set the structure_mod flag.
Set the symmetrization flag.
"""
if not isinstance(symmetrization, bool):
raise TypeError("Symmetrization should be a boolean.")
Expand Down
31 changes: 26 additions & 5 deletions src/mindlessgen/symmetrization/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
This module defines the abstract base class for all structure modification methods.
This module defines the abstract base class for all symmetrization methods.
"""

from abc import ABC, abstractmethod
Expand All @@ -12,12 +12,12 @@

class Symmetrizer(ABC):
"""
This abstract base class defines the interface for all structure modification methods.
This abstract base class defines the interface for all symmetrization methods.
"""

def __init__(self, config: SymmetrizationConfig):
"""
Initialize the structure modification class.
Initialize the symmetrization class.
"""
self.cfg = config

Expand All @@ -28,11 +28,11 @@ def _modify_structure(
translation_distance: float,
) -> Molecule:
"""
Define the structure modification process.
Define the symmetrization process.
Arguments:
molecule (Molecule): Molecule to modify
config (StructureModConfig): Configuration for the structure modification
translation_distance (float): Distance to translate the molecule
Returns:
Molecule: Modified molecule
Expand All @@ -46,6 +46,13 @@ def translation(
) -> Molecule:
"""
Translate the molecule and add a little extra distance to the x axis.
Arguments:
mol (Molecule): Molecule to translate
x_vec_translation (float): Translation distance in x direction
Returns:
Molecule: Translated molecule
"""
xyz = mol.xyz
# Find the translation vector in x direction
Expand All @@ -67,6 +74,14 @@ def combine_structure(
) -> Molecule:
"""
Combine the original and the modified molecule.
Arguments:
original_mol (Molecule): Original molecule
new_mol (Molecule): Modified molecule
addxyz (np.ndarray): Coordinates to add to the molecule
Returns:
Molecule: Combined molecule
"""
new_mol.xyz = np.vstack((new_mol.xyz, addxyz))
# add dimension of addxyz to the number of atoms
Expand All @@ -84,6 +99,12 @@ def get_symmetric_structure(
) -> Molecule:
"""
Get the symmetric structure of the molecule.
Arguments:
mol (Molecule): Molecule to symmetrize
Returns:
Molecule: Symmetric molecule
"""
orig_mol = mol.copy()
if not check_distances(mol.xyz, mol.ati, 0.6):
Expand Down
5 changes: 2 additions & 3 deletions src/mindlessgen/symmetrization/inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ def _modify_structure(
Invert the molecule.
"""
mol = self.translation(mol, translation_distance)
xyz = mol.xyz
inversion_matrix = np.array([[-1, 0, 0], [0, -1, 0], [0, 0, -1]])
xyz_inversion = xyz.copy()
xyz_inversion = mol.xyz.copy()
modified_molecule = mol.copy()
for i in range(mol.num_atoms):
xyz_inversion[i] = np.dot(inversion_matrix, xyz[i])
xyz_inversion[i] = np.dot(inversion_matrix, mol.xyz[i])
modified_molecule = self.combine_structure(
mol, modified_molecule, xyz_inversion
)
Expand Down
5 changes: 2 additions & 3 deletions src/mindlessgen/symmetrization/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ def _modify_structure(
Mirror the molecule.
"""
mol = self.translation(mol, translation_distance)
xyz = mol.xyz
mirror_matrix = np.array([[-1, 0, 0], [0, 1, 0], [0, 0, 1]])
xyz_mirror = xyz.copy()
xyz_mirror = mol.xyz.copy()
modified_molecule = mol.copy()
for i in range(mol.num_atoms):
xyz_mirror[i] = np.dot(mirror_matrix, xyz[i])
xyz_mirror[i] = np.dot(mirror_matrix, mol.xyz[i])
# Combine the original and the mirror image
modified_molecule = self.combine_structure(mol, modified_molecule, xyz_mirror)
return modified_molecule
3 changes: 1 addition & 2 deletions src/mindlessgen/symmetrization/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def _modify_structure(
Rotate the molecule around the z-axis.
"""
mol = self.translation(mol, translation_distance)
xyz = mol.xyz
n = self.cfg.rotation
rotation_matrix = np.array(
[
Expand All @@ -31,7 +30,7 @@ def _modify_structure(
[0, 0, 1],
]
)
xyz_rotation = xyz.copy()
xyz_rotation = mol.xyz.copy()
modified_molecule = mol.copy()
# For loop to get n times the molecule
for _ in range(1, n):
Expand Down

0 comments on commit 379b6ab

Please sign in to comment.