diff --git a/python/BioSimSpace/Parameters/_Protocol/_openforcefield.py b/python/BioSimSpace/Parameters/_Protocol/_openforcefield.py index 7c3aed05a..018f43e4e 100644 --- a/python/BioSimSpace/Parameters/_Protocol/_openforcefield.py +++ b/python/BioSimSpace/Parameters/_Protocol/_openforcefield.py @@ -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. @@ -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 @@ -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 @@ -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 diff --git a/python/BioSimSpace/Parameters/_parameters.py b/python/BioSimSpace/Parameters/_parameters.py index 07a49d24b..6e8570bb9 100644 --- a/python/BioSimSpace/Parameters/_parameters.py +++ b/python/BioSimSpace/Parameters/_parameters.py @@ -463,6 +463,7 @@ def _parameterise_openff( forcefield, molecule, ensure_compatible=True, + use_nagl=True, work_dir=None, property_map={}, **kwargs, @@ -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. @@ -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 @@ -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. @@ -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. @@ -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, ) diff --git a/python/BioSimSpace/Sandpit/Exscientia/Parameters/_Protocol/_openforcefield.py b/python/BioSimSpace/Sandpit/Exscientia/Parameters/_Protocol/_openforcefield.py index 7c3aed05a..018f43e4e 100644 --- a/python/BioSimSpace/Sandpit/Exscientia/Parameters/_Protocol/_openforcefield.py +++ b/python/BioSimSpace/Sandpit/Exscientia/Parameters/_Protocol/_openforcefield.py @@ -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. @@ -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 @@ -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 @@ -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 diff --git a/python/BioSimSpace/Sandpit/Exscientia/Parameters/_parameters.py b/python/BioSimSpace/Sandpit/Exscientia/Parameters/_parameters.py index 07a49d24b..6e8570bb9 100644 --- a/python/BioSimSpace/Sandpit/Exscientia/Parameters/_parameters.py +++ b/python/BioSimSpace/Sandpit/Exscientia/Parameters/_parameters.py @@ -463,6 +463,7 @@ def _parameterise_openff( forcefield, molecule, ensure_compatible=True, + use_nagl=True, work_dir=None, property_map={}, **kwargs, @@ -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. @@ -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 @@ -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. @@ -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. @@ -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, )