Skip to content

Commit

Permalink
Merge pull request #282 from nlesc-nano/psf
Browse files Browse the repository at this point in the history
BUG: Fix an issue with parsing multiple ligands in `generate_psf2`
  • Loading branch information
BvB93 committed Sep 29, 2022
2 parents fcb1097 + 3a8117d commit 1103fab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
6 changes: 6 additions & 0 deletions FOX/functions/molecule_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def fix_bond_orders(mol: Molecule) -> None:
if at2_saturation != 0:
at2.properties.charge += at2_saturation

# Explicitly cast integer-valued floats to int
for at in mol:
charge = at.properties.charge
if isinstance(charge, float) and charge.is_integer():
at.properties.charge = int(charge)


def separate_mod(mol: Molecule) -> List[List[int]]:
"""Modified version of the PLAMS Molecule.separate_ method.
Expand Down
17 changes: 3 additions & 14 deletions FOX/recipes/psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,6 @@ def generate_psf2(
"""
if not isinstance(qd, Molecule):
qd = Molecule(qd)
if not len(qd.bonds):
warnings.warn(
f'Failed to identify any bonds in the following qd: {qd.get_formula()}',
category=MoleculeWarning,
)

# Create a dictionary with RDKit molecules and the number of atoms contained therein
rdmol_dict = _get_rddict(ligands)
Expand All @@ -375,7 +370,7 @@ def generate_psf2(
for ref, k in rdmol_dict.items():
k = 0 if ref is ref0 else k
new = _update_lig(new, k, copy=False)
j += k
j = k or j

if _get_matches(new, ref):
qd.bonds += [Bond(atom1=qd[bond.atom1.id],
Expand All @@ -389,7 +384,7 @@ def generate_psf2(

else:
err = (f'Failed to identify any ligands {ligands} within the range '
f'[{i}:{i + next(iter(rdmol_dict.items()))[1]}]')
f'[{i}:{i + j}]')
if not ret_failed_lig:
raise MoleculeError(err)
else:
Expand Down Expand Up @@ -536,13 +531,7 @@ def _get_rddict(ligands: Iterable[str | Molecule | Mol]) -> Dict[Mol, int]:
f'Failed to identify any bonds in the following ligands: {no_bonds!r}',
category=MoleculeWarning, stacklevel=2,
)

v_old = 0
rdmol_dict = {}
for (_, k), v in _items_sorted(tmp_dct):
rdmol_dict[k] = v - v_old
v_old = v
return rdmol_dict
return {k: v for (_, k), v in _items_sorted(tmp_dct)}


def set_integer_bonds(self) -> None:
Expand Down

0 comments on commit 1103fab

Please sign in to comment.