Initial Work on Reading Crystal and Creation Gaussian Input

This commit is contained in:
2022-12-26 06:49:14 -03:00
parent 787d17eccd
commit 3716017cb0
30 changed files with 3262 additions and 852 deletions

View File

@@ -0,0 +1,43 @@
from crystalpol.shared.system.molecule import Molecule
from typing import List
class Crystal:
"""
This class represents a crystal, it will be organized in a list structure.
Each element is a unitary cell in the crystal. And this unitary cell will have
Molecules in it.
"""
def __init__(self, structure: List[List[str]]):
self.structure = structure
self.cells = []
def __iter__(self):
for cell in self.cells:
yield cell
def __len__(self):
return len(self.cells)
def __getitem__(self, index):
return self.cells[index]
def add_cell(self, cell: List[Molecule]) -> None:
valid = self._is_valid_cell(cell)
if not valid:
raise ValueError(
"This cell does not obey the declared format for this Crystal."
)
else:
self.cells.append(cell)
def _is_valid_cell(self, cell: List[Molecule]) -> bool:
if len(cell) == len(self.structure):
for i, molecule in enumerate(cell):
if len(molecule.atoms) == len(self.structure[i]) \
and all(atom.symbol == self.structure[i][j] for j, atom in enumerate(molecule.atoms)):
return True
return False