Skip to content

Commit

Permalink
Add working instructions for deleting constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshanuikabundi committed Sep 10, 2024
1 parent 8f83358 commit 4daf451
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
31 changes: 27 additions & 4 deletions source/_ext/check_python_codeblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,48 @@

molecule = Molecule.from_smiles("C123C(C1)(C2)C3")
topology = Topology.from_molecules([molecule])
force_field = ForceField("openff_unconstrained-2.2.0.offxml")
force_field = ForceField("openff_unconstrained-2.2.0.offxml")
ff_unconstrained = force_field
ff_constrained = ForceField("openff-2.2.0.offxml")

# Set the import hook
import sys
import builtins
import sys

_old_import = __import__
_already_deleted = False


def __import__(name, *args, **kwargs):
"""
Clear above variables on any new import of the toolkit
"""
global _already_deleted
if name.startswith("openff.toolkit") and not _already_deleted:
global molecule, topology, force_field, ForceField, Molecule, Topology
del molecule, topology, force_field, ForceField, Molecule, Topology
global \
molecule, \
topology, \
force_field, \
ForceField, \
Molecule, \
Topology, \
ff_constrained, \
ff_unconstrained
del (
molecule,
topology,
force_field,
ForceField,
Molecule,
Topology,
ff_constrained,
ff_unconstrained,
)
_already_deleted = True

return _old_import(name, *args, **kwargs)


builtins.__import__ = __import__

# Execute the code block
Expand Down
8 changes: 7 additions & 1 deletion source/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,14 @@ Hydrogen-involving bonds are constrained with a single constraint entry in a `.o
Adding or removing the inner `<Constraint...` line will convert a force field between being constrained and unconstrained. A [`ForceField`](openff.toolkit.typing.engines.smirnoff.forcefield.ForceField) object can constrain its bonds involving hydrogen by adding the relevant parameter to its `'Constraints'` parameter handler:

```python
ch = force_field.get_parameter_handler('Constraints')
ch = ff_unconstrained.get_parameter_handler('Constraints')
ch.add_parameter({'smirks': "[#1:1]-[*:2]"})
```

Constraints can be removed from bonds involving hydrogen by removing the corresponding parameter:

```python
del ff_constrained['Constraints'].parameters["[#1:1]-[*:2]"]
```

:::::

0 comments on commit 4daf451

Please sign in to comment.