Skip to content

Commit

Permalink
Fixed an issue where charge and spinpol were not being read if the se…
Browse files Browse the repository at this point in the history
…cond method of fragment specification is used
  • Loading branch information
YHordijk committed Feb 7, 2024
1 parent fc5963f commit 281a19f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
7 changes: 5 additions & 2 deletions examples/job/NaCl.xyz
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
2

Na 0 0 2 frag=Na
Cl 0 0 0 frag=Cl
Na 0 0 2
Cl 0 0 0


frag_Na = 1
frag_Cl = 2
charge_Na = 1
charge_Cl = -1
13 changes: 7 additions & 6 deletions src/tcutility/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def guess_fragments(mol: plams.Molecule) -> Dict[str, plams.Molecule]:
if len(fragment_flags) > 0:
fragment_mols = {frag.removeprefix('frag_'): plams.Molecule() for frag in fragment_flags}
for frag in fragment_flags:
frag_name = frag.removeprefix('frag_')
indices = []
index_line = ensure_list(mol.flags[frag])
for indx in index_line:
Expand All @@ -204,12 +205,12 @@ def guess_fragments(mol: plams.Molecule) -> Dict[str, plams.Molecule]:
else:
raise ValueError(f'Fragment index {indx} could not be parsed.')

[fragment_mols[frag.removeprefix('frag_')].add_atom(mol[i]) for i in indices]
fragment_mols[frag.removeprefix('frag_')].flags = {'tags': set()}
if f'charge_{frag}' in mol.flags:
fragment_mols[frag.removeprefix('frag_')].flags['charge'] = mol.flags[f'charge_{frag}']
if f'spinpol_{frag}' in mol.flags:
fragment_mols[frag.removeprefix('frag_')].flags['spinpol'] = mol.flags[f'spinpol_{frag}']
[fragment_mols[frag_name].add_atom(mol[i]) for i in indices]
fragment_mols[frag_name].flags = {'tags': set()}
if f'charge_{frag_name}' in mol.flags:
fragment_mols[frag_name].flags['charge'] = mol.flags[f'charge_{frag_name}']
if f'spinpol_{frag_name}' in mol.flags:
fragment_mols[frag_name].flags['spinpol'] = mol.flags[f'spinpol_{frag_name}']

return fragment_mols

Expand Down
7 changes: 5 additions & 2 deletions test/fixtures/xyz/NaCl.xyz
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
2

Na 0 0 2 frag=Na
Cl 0 0 0 frag=Cl
Na 0 0 2
Cl 0 0 0


frag_Na = 1
frag_Cl = 2
charge_Na = 1
charge_Cl = -1

0 comments on commit 281a19f

Please sign in to comment.