From 3870c74001cb0bb6888cbd840d393869a133a488 Mon Sep 17 00:00:00 2001 From: Yuman Hordijk Date: Thu, 24 Oct 2024 14:54:29 +0200 Subject: [PATCH] Added the from_string function to molecule --- src/tcutility/molecule.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/tcutility/molecule.py b/src/tcutility/molecule.py index 67be5479..9b12c6c0 100644 --- a/src/tcutility/molecule.py +++ b/src/tcutility/molecule.py @@ -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]: """