Skip to content

Commit

Permalink
Allow user to choose to use NAGL to generate AM1-BCC charges.
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Mar 25, 2024
1 parent 9355e30 commit 0e2bb92
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 8 deletions.
17 changes: 15 additions & 2 deletions python/BioSimSpace/Parameters/_Protocol/_openforcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@
class OpenForceField(_protocol.Protocol):
"""A class for handling protocols for Open Force Field models."""

def __init__(self, forcefield, ensure_compatible=True, property_map={}):
def __init__(
self, forcefield, ensure_compatible=True, use_nagl=True, property_map={}
):
"""
Constructor.
Expand All @@ -145,6 +147,11 @@ def __init__(self, forcefield, ensure_compatible=True, property_map={}):
original molecule, e.g. the original atom and residue names will be
kept.
use_nagl : bool
Whether to use NAGL to compute AM1-BCC charges. If False, the default
is to use AmberTools via antechamber and sqm. (This option is only
used if NAGL is available.)
property_map : dict
A dictionary that maps system "properties" to their user defined
values. This allows the user to refer to properties with their
Expand All @@ -158,6 +165,12 @@ def __init__(self, forcefield, ensure_compatible=True, property_map={}):
property_map=property_map,
)

if not isinstance(use_nagl, bool):
raise TypeError("'use_nagl' must be of type 'bool'")

# Set the NAGL flag.
self._use_nagl = use_nagl

# Set the compatibility flags.
self._tleap = False
self._pdb2gmx = False
Expand Down Expand Up @@ -314,7 +327,7 @@ def run(self, molecule, work_dir=None, queue=None):
raise _ThirdPartyError(msg) from None

# Apply AM1-BCC charges using NAGL.
if _has_nagl:
if _has_nagl and self._use_nagl:
try:
_nagl.assign_partial_charges(
off_molecule, partial_charge_method=_nagl_model
Expand Down
27 changes: 25 additions & 2 deletions python/BioSimSpace/Parameters/_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def _parameterise_openff(
forcefield,
molecule,
ensure_compatible=True,
use_nagl=True,
work_dir=None,
property_map={},
**kwargs,
Expand All @@ -489,6 +490,11 @@ def _parameterise_openff(
the parameterised molecule will preserve the topology of the original
molecule, e.g. the original atom and residue names will be kept.
use_nagl : bool
Whether to use NAGL to compute AM1-BCC charges. If False, the default
is to use AmberTools via antechamber and sqm. (This option is only
used if NAGL is available.)
work_dir : str
The working directory for the process.
Expand Down Expand Up @@ -583,12 +589,21 @@ def _parameterise_openff(
if forcefield not in _forcefields_lower:
raise ValueError("Supported force fields are: %s" % openForceFields())

if not isinstance(ensure_compatible, bool):
raise TypeError("'ensure_compatible' must be of type 'bool'.")

if not isinstance(use_nagl, bool):
raise TypeError("'use_nagl' must be of type 'bool'.")

if not isinstance(property_map, dict):
raise TypeError("'property_map' must be of type 'dict'")

# Create a default protocol.
protocol = _Protocol.OpenForceField(
forcefield, ensure_compatible=ensure_compatible, property_map=property_map
forcefield,
ensure_compatible=ensure_compatible,
use_nagl=use_nagl,
property_map=property_map,
)

# Run the parameterisation protocol in the background and return
Expand Down Expand Up @@ -1079,7 +1094,9 @@ def _function(
# it conforms to sensible function naming standards, i.e. "-" and "."
# characters replaced by underscores.
def _make_openff_function(name):
def _function(molecule, ensure_compatible=True, work_dir=None, property_map={}):
def _function(
molecule, ensure_compatible=True, use_nagl=True, work_dir=None, property_map={}
):
"""
Parameterise a molecule using the named force field from the
Open Force Field initiative.
Expand All @@ -1100,6 +1117,11 @@ def _function(molecule, ensure_compatible=True, work_dir=None, property_map={}):
molecule will preserve the topology of the original molecule, e.g.
the original atom and residue names will be kept.
use_nagl : bool
Whether to use NAGL to compute AM1-BCC charges. If False, the default
is to use AmberTools via antechamber and sqm. (This option is only
used if NAGL is available.)
work_dir : str
The working directory for the process.
Expand All @@ -1118,6 +1140,7 @@ def _function(molecule, ensure_compatible=True, work_dir=None, property_map={}):
name,
molecule,
ensure_compatible=ensure_compatible,
use_nagl=use_nagl,
work_dir=work_dir,
property_map=property_map,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@
class OpenForceField(_protocol.Protocol):
"""A class for handling protocols for Open Force Field models."""

def __init__(self, forcefield, ensure_compatible=True, property_map={}):
def __init__(
self, forcefield, ensure_compatible=True, use_nagl=True, property_map={}
):
"""
Constructor.
Expand All @@ -145,6 +147,11 @@ def __init__(self, forcefield, ensure_compatible=True, property_map={}):
original molecule, e.g. the original atom and residue names will be
kept.
use_nagl : bool
Whether to use NAGL to compute AM1-BCC charges. If False, the default
is to use AmberTools via antechamber and sqm. (This option is only
used if NAGL is available.)
property_map : dict
A dictionary that maps system "properties" to their user defined
values. This allows the user to refer to properties with their
Expand All @@ -158,6 +165,12 @@ def __init__(self, forcefield, ensure_compatible=True, property_map={}):
property_map=property_map,
)

if not isinstance(use_nagl, bool):
raise TypeError("'use_nagl' must be of type 'bool'")

# Set the NAGL flag.
self._use_nagl = use_nagl

# Set the compatibility flags.
self._tleap = False
self._pdb2gmx = False
Expand Down Expand Up @@ -314,7 +327,7 @@ def run(self, molecule, work_dir=None, queue=None):
raise _ThirdPartyError(msg) from None

# Apply AM1-BCC charges using NAGL.
if _has_nagl:
if _has_nagl and self._use_nagl:
try:
_nagl.assign_partial_charges(
off_molecule, partial_charge_method=_nagl_model
Expand Down
27 changes: 25 additions & 2 deletions python/BioSimSpace/Sandpit/Exscientia/Parameters/_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def _parameterise_openff(
forcefield,
molecule,
ensure_compatible=True,
use_nagl=True,
work_dir=None,
property_map={},
**kwargs,
Expand All @@ -489,6 +490,11 @@ def _parameterise_openff(
the parameterised molecule will preserve the topology of the original
molecule, e.g. the original atom and residue names will be kept.
use_nagl : bool
Whether to use NAGL to compute AM1-BCC charges. If False, the default
is to use AmberTools via antechamber and sqm. (This option is only
used if NAGL is available.)
work_dir : str
The working directory for the process.
Expand Down Expand Up @@ -583,12 +589,21 @@ def _parameterise_openff(
if forcefield not in _forcefields_lower:
raise ValueError("Supported force fields are: %s" % openForceFields())

if not isinstance(ensure_compatible, bool):
raise TypeError("'ensure_compatible' must be of type 'bool'.")

if not isinstance(use_nagl, bool):
raise TypeError("'use_nagl' must be of type 'bool'.")

if not isinstance(property_map, dict):
raise TypeError("'property_map' must be of type 'dict'")

# Create a default protocol.
protocol = _Protocol.OpenForceField(
forcefield, ensure_compatible=ensure_compatible, property_map=property_map
forcefield,
ensure_compatible=ensure_compatible,
use_nagl=use_nagl,
property_map=property_map,
)

# Run the parameterisation protocol in the background and return
Expand Down Expand Up @@ -1079,7 +1094,9 @@ def _function(
# it conforms to sensible function naming standards, i.e. "-" and "."
# characters replaced by underscores.
def _make_openff_function(name):
def _function(molecule, ensure_compatible=True, work_dir=None, property_map={}):
def _function(
molecule, ensure_compatible=True, use_nagl=True, work_dir=None, property_map={}
):
"""
Parameterise a molecule using the named force field from the
Open Force Field initiative.
Expand All @@ -1100,6 +1117,11 @@ def _function(molecule, ensure_compatible=True, work_dir=None, property_map={}):
molecule will preserve the topology of the original molecule, e.g.
the original atom and residue names will be kept.
use_nagl : bool
Whether to use NAGL to compute AM1-BCC charges. If False, the default
is to use AmberTools via antechamber and sqm. (This option is only
used if NAGL is available.)
work_dir : str
The working directory for the process.
Expand All @@ -1118,6 +1140,7 @@ def _function(molecule, ensure_compatible=True, work_dir=None, property_map={}):
name,
molecule,
ensure_compatible=ensure_compatible,
use_nagl=use_nagl,
work_dir=work_dir,
property_map=property_map,
)
Expand Down

0 comments on commit 0e2bb92

Please sign in to comment.