Skip to content

Commit

Permalink
Added the from_string function to molecule
Browse files Browse the repository at this point in the history
  • Loading branch information
YHordijk committed Oct 24, 2024
1 parent 25eac1a commit 3870c74
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/tcutility/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,28 @@ def parse_flags(args):

return mol

def from_string(s: str) -> plams.Molecule:
mol = plams.Molecule()
for line in s.splitlines():
parts = [parse_str(part) for part in line.split()]
if len(parts) < 4:
continue

# check if first part is the symbol of the molecule
if not isinstance(parts[0], str) and len(parts[0]) > 2:
continue

# check if
if not all(isinstance(part, (float, int)) for part in parts[1:4]):
continue

atom = plams.Atom(symbol=parts[0], coords=parts[1:4])
mol.add_atom(atom)

return mol




def guess_fragments(mol: plams.Molecule) -> Dict[str, plams.Molecule]:
"""
Expand Down

0 comments on commit 3870c74

Please sign in to comment.