Skip to content

Commit

Permalink
abstract structure merge; minor revisions for config
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 09c6f73 commit a6b61d5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
21 changes: 21 additions & 0 deletions src/mindlessgen/Structure_modification/StrucMod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from abc import ABC, abstractmethod

import numpy as np

from mindlessgen.molecules.molecule import Molecule
from mindlessgen.prog.config import StructureModConfig

Expand Down Expand Up @@ -52,3 +54,22 @@ def translation(
xyz[i, 0] += xshift
mol.xyz = xyz
return mol

def combine_structure(
self,
original_mol: Molecule,
new_mol: Molecule,
addxyz: np.ndarray,
) -> Molecule:
"""
Combine the original and the modified molecule.
"""
new_mol.xyz = np.vstack((new_mol.xyz, addxyz))
# add dimension of addxyz to the number of atoms
new_mol.num_atoms += original_mol.num_atoms
new_mol.ati = np.hstack((new_mol.ati, original_mol.ati))
new_mol.charge += original_mol.charge
new_mol.uhf += original_mol.uhf
new_mol.atlist += original_mol.atlist
new_mol.set_name_from_formula()
return new_mol
11 changes: 3 additions & 8 deletions src/mindlessgen/Structure_modification/inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ def modify_structure(
modified_molecule = mol.copy()
for i in range(mol.num_atoms):
xyz_inversion[i] = np.dot(inversion_matrix, xyz[i])
xyz_combined = np.vstack((xyz, xyz_inversion))
modified_molecule.xyz = xyz_combined
modified_molecule.num_atoms += mol.num_atoms
modified_molecule.ati = np.hstack((modified_molecule.ati, mol.ati))
modified_molecule.charge += mol.charge
modified_molecule.uhf += mol.uhf
modified_molecule.atlist += mol.atlist
modified_molecule.set_name_from_formula()
modified_molecule = self.combine_structure(
mol, modified_molecule, xyz_inversion
)
return modified_molecule
9 changes: 1 addition & 8 deletions src/mindlessgen/Structure_modification/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,5 @@ def modify_structure(
for i in range(mol.num_atoms):
xyz_mirror[i] = np.dot(mirror_matrix, xyz[i])
# Combine the original and the mirror image
xyz_combined = np.vstack((xyz, xyz_mirror))
modified_molecule.xyz = xyz_combined
modified_molecule.num_atoms += mol.num_atoms
modified_molecule.ati = np.hstack((modified_molecule.ati, mol.ati))
modified_molecule.charge += mol.charge
modified_molecule.uhf += mol.uhf
modified_molecule.atlist += mol.atlist
modified_molecule.set_name_from_formula()
modified_molecule = self.combine_structure(mol, modified_molecule, xyz_mirror)
return modified_molecule
11 changes: 3 additions & 8 deletions src/mindlessgen/Structure_modification/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ def modify_structure(
for _ in range(1, n):
for k in range(mol.num_atoms):
xyz_rotation[k] = np.dot(rotation_matrix, xyz_rotation[k])
xyz = np.vstack((xyz, xyz_rotation))
modified_molecule.num_atoms += mol.num_atoms
modified_molecule.ati = np.hstack((modified_molecule.ati, mol.ati))
modified_molecule.charge += mol.charge
modified_molecule.uhf += mol.uhf
modified_molecule.atlist += mol.atlist
modified_molecule.xyz = xyz
modified_molecule.set_name_from_formula()
modified_molecule = self.combine_structure(
mol, modified_molecule, xyz_rotation
)
return modified_molecule
6 changes: 3 additions & 3 deletions src/mindlessgen/prog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,11 +1171,11 @@ def operation(self, operation: str):
raise ValueError(
"Rotation operations should be in the format 'c_<n>_rotation' where <n> is an integer."
)
self._rotation = int(parts[1])
self.rotation = int(parts[1])
else:
self._rotation = None
self.rotation = None

if operation.split("_")[0] not in ["translation", "c", "mirror", "inversion"]:
if operation.split("_")[0] not in ["c", "mirror", "inversion"]:
raise ValueError(
"Operation can only be translation, c_<n>_rotation, mirror or inversion."
)
Expand Down

0 comments on commit a6b61d5

Please sign in to comment.