Skip to content

Commit 3364c2c

Browse files
authored
Merge pull request #482 from OpenBioSim/fix_ghost_sigmas
Make zeroing of dummy atom LJ sigmas optional
2 parents d618222 + 63fdb75 commit 3364c2c

1 file changed

Lines changed: 39 additions & 26 deletions

File tree

python/BioSimSpace/Align/_merge.py

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def merge(
3333
mapping,
3434
allow_ring_breaking=False,
3535
allow_ring_size_change=False,
36+
fix_perturbable_zero_sigmas=False,
3637
force=False,
3738
roi=None,
3839
property_map0={},
@@ -59,6 +60,9 @@ def merge(
5960
allow_ring_size_change : bool
6061
Whether to allow changes in ring size.
6162
63+
fix_perturbable_zero_sigmas : bool
64+
Whether to prevent sigma values being perturbed to zero.
65+
6266
force : bool
6367
Whether to try to force the merge, even when the molecular
6468
connectivity changes not as the result of a ring transformation.
@@ -122,6 +126,9 @@ def merge(
122126
if not isinstance(allow_ring_size_change, bool):
123127
raise TypeError("'allow_ring_size_change' must be of type 'bool'")
124128

129+
if not isinstance(fix_perturbable_zero_sigmas, bool):
130+
raise TypeError("'fix_perturbable_zero_sigmas' must be of type 'bool'")
131+
125132
if not isinstance(force, bool):
126133
raise TypeError("'force' must be of type 'bool'")
127134

@@ -751,33 +758,39 @@ def merge(
751758
.molecule()
752759
)
753760

754-
# Tolerance for zero sigma values.
755-
null_lj_sigma = 1e-9
756-
757-
# Atoms with zero LJ sigma values need to have their sigma values set to the
758-
# value from the other end state.
759-
for atom in edit_mol.atoms():
760-
# Get the end state LJ sigma values.
761-
lj0 = atom.property("LJ0")
762-
lj1 = atom.property("LJ1")
763-
764-
# Lambda = 0 state has a zero sigma value.
765-
if abs(lj0.sigma().value()) <= null_lj_sigma:
766-
# Use the sigma value from the lambda = 1 state.
767-
edit_mol = (
768-
edit_mol.atom(atom.index())
769-
.set_property("LJ0", _SireMM.LJParameter(lj1.sigma(), lj0.epsilon()))
770-
.molecule()
771-
)
761+
# Prevent sigma values being perturbed to zero.
762+
if fix_perturbable_zero_sigmas:
763+
# Tolerance for zero sigma values.
764+
null_lj_sigma = 1e-9
765+
766+
# Atoms with zero LJ sigma values need to have their sigma values set to the
767+
# value from the other end state.
768+
for atom in edit_mol.atoms():
769+
# Get the end state LJ sigma values.
770+
lj0 = atom.property("LJ0")
771+
lj1 = atom.property("LJ1")
772+
773+
# Lambda = 0 state has a zero sigma value.
774+
if abs(lj0.sigma().value()) <= null_lj_sigma:
775+
# Use the sigma value from the lambda = 1 state.
776+
edit_mol = (
777+
edit_mol.atom(atom.index())
778+
.set_property(
779+
"LJ0", _SireMM.LJParameter(lj1.sigma(), lj0.epsilon())
780+
)
781+
.molecule()
782+
)
772783

773-
# Lambda = 1 state has a zero sigma value.
774-
if abs(lj1.sigma().value()) <= null_lj_sigma:
775-
# Use the sigma value from the lambda = 0 state.
776-
edit_mol = (
777-
edit_mol.atom(atom.index())
778-
.set_property("LJ1", _SireMM.LJParameter(lj0.sigma(), lj1.epsilon()))
779-
.molecule()
780-
)
784+
# Lambda = 1 state has a zero sigma value.
785+
if abs(lj1.sigma().value()) <= null_lj_sigma:
786+
# Use the sigma value from the lambda = 0 state.
787+
edit_mol = (
788+
edit_mol.atom(atom.index())
789+
.set_property(
790+
"LJ1", _SireMM.LJParameter(lj0.sigma(), lj1.epsilon())
791+
)
792+
.molecule()
793+
)
781794

782795
# We now need to merge "bond", "angle", "dihedral", and "improper" parameters.
783796
# To do so, we extract the properties from molecule1, then add the additional

0 commit comments

Comments
 (0)