diff --git a/python/BioSimSpace/Parameters/_Protocol/_amber.py b/python/BioSimSpace/Parameters/_Protocol/_amber.py index 6694cf572..8ba8fab45 100644 --- a/python/BioSimSpace/Parameters/_Protocol/_amber.py +++ b/python/BioSimSpace/Parameters/_Protocol/_amber.py @@ -841,6 +841,7 @@ def __init__( net_charge=None, ensure_compatible=True, property_map={}, + **kwargs, ): """ Constructor. @@ -873,6 +874,10 @@ def __init__( A dictionary that maps system "properties" to their user defined values. This allows the user to refer to properties with their own naming scheme, e.g. { "charge" : "my-charge" } + + **kwargs: dict + Additional keyword arguments. These can be used to pass custom + parameters to the Antechamber program. """ if type(version) is not int: @@ -912,6 +917,11 @@ def __init__( "'net_charge' must be of type 'int', or `BioSimSpace.Types.Charge'" ) + # Check the kwargs to see whether acdoctor is enabled. + self._acdoctor = kwargs.get("acdoctor", True) + if not isinstance(self._acdoctor, bool): + raise TypeError("'acdoctor' must be of type 'bool'") + # Set the version. self._version = version @@ -1086,6 +1096,10 @@ def run(self, molecule, work_dir=None, queue=None): charge, ) + # Disable acdoctor if requested. + if not self._acdoctor: + command += " -dr no" + with open(_os.path.join(str(work_dir), "README.txt"), "w") as file: # Write the command to file. file.write("# Antechamber was run with the following command:\n") diff --git a/python/BioSimSpace/Parameters/_parameters.py b/python/BioSimSpace/Parameters/_parameters.py index 825e71490..92df02388 100644 --- a/python/BioSimSpace/Parameters/_parameters.py +++ b/python/BioSimSpace/Parameters/_parameters.py @@ -362,6 +362,7 @@ def gaff( charge_method=charge_method, ensure_compatible=ensure_compatible, property_map=property_map, + **kwargs, ) # Run the parameterisation protocol in the background and return @@ -460,6 +461,7 @@ def gaff2( charge_method=charge_method, ensure_compatible=ensure_compatible, property_map=property_map, + **kwargs, ) # Run the parameterisation protocol in the background and return diff --git a/python/BioSimSpace/Sandpit/Exscientia/Parameters/_Protocol/_amber.py b/python/BioSimSpace/Sandpit/Exscientia/Parameters/_Protocol/_amber.py index 6694cf572..8ba8fab45 100644 --- a/python/BioSimSpace/Sandpit/Exscientia/Parameters/_Protocol/_amber.py +++ b/python/BioSimSpace/Sandpit/Exscientia/Parameters/_Protocol/_amber.py @@ -841,6 +841,7 @@ def __init__( net_charge=None, ensure_compatible=True, property_map={}, + **kwargs, ): """ Constructor. @@ -873,6 +874,10 @@ def __init__( A dictionary that maps system "properties" to their user defined values. This allows the user to refer to properties with their own naming scheme, e.g. { "charge" : "my-charge" } + + **kwargs: dict + Additional keyword arguments. These can be used to pass custom + parameters to the Antechamber program. """ if type(version) is not int: @@ -912,6 +917,11 @@ def __init__( "'net_charge' must be of type 'int', or `BioSimSpace.Types.Charge'" ) + # Check the kwargs to see whether acdoctor is enabled. + self._acdoctor = kwargs.get("acdoctor", True) + if not isinstance(self._acdoctor, bool): + raise TypeError("'acdoctor' must be of type 'bool'") + # Set the version. self._version = version @@ -1086,6 +1096,10 @@ def run(self, molecule, work_dir=None, queue=None): charge, ) + # Disable acdoctor if requested. + if not self._acdoctor: + command += " -dr no" + with open(_os.path.join(str(work_dir), "README.txt"), "w") as file: # Write the command to file. file.write("# Antechamber was run with the following command:\n") diff --git a/python/BioSimSpace/Sandpit/Exscientia/Parameters/_parameters.py b/python/BioSimSpace/Sandpit/Exscientia/Parameters/_parameters.py index 825e71490..92df02388 100644 --- a/python/BioSimSpace/Sandpit/Exscientia/Parameters/_parameters.py +++ b/python/BioSimSpace/Sandpit/Exscientia/Parameters/_parameters.py @@ -362,6 +362,7 @@ def gaff( charge_method=charge_method, ensure_compatible=ensure_compatible, property_map=property_map, + **kwargs, ) # Run the parameterisation protocol in the background and return @@ -460,6 +461,7 @@ def gaff2( charge_method=charge_method, ensure_compatible=ensure_compatible, property_map=property_map, + **kwargs, ) # Run the parameterisation protocol in the background and return diff --git a/tests/Parameters/test_parameters.py b/tests/Parameters/test_parameters.py index e9c07cc13..54e544299 100644 --- a/tests/Parameters/test_parameters.py +++ b/tests/Parameters/test_parameters.py @@ -167,3 +167,24 @@ def test_smiles_stereo(): # Make sure the SMILES strings are the same. assert rdmol0_smiles == rdmol1_smiles + + +@pytest.mark.skipif( + has_antechamber is False or has_tleap is False, + reason="Requires AmberTools/antechamber and tLEaP to be installed.", +) +def test_acdoctor(): + """ + Test that parameterising negatively charged molecules works when acdoctor + is disabled. + """ + + # Load the molecule. + mol = BSS.IO.readMolecules(f"{url}/negative_charge.sdf")[0] + + # Make sure parameterisation fails when acdoctor is enabled. + with pytest.raises(BSS._Exceptions.ParameterisationError): + BSS.Parameters.gaff(mol).getMolecule() + + # Make sure parameterisation works when acdoctor is disabled. + mol = BSS.Parameters.gaff(mol, acdoctor=False).getMolecule() diff --git a/tests/Sandpit/Exscientia/Parameters/test_parameters.py b/tests/Sandpit/Exscientia/Parameters/test_parameters.py index 00bb088b2..2bee56ebb 100644 --- a/tests/Sandpit/Exscientia/Parameters/test_parameters.py +++ b/tests/Sandpit/Exscientia/Parameters/test_parameters.py @@ -172,3 +172,24 @@ def test_smiles_stereo(): # Make sure the SMILES strings are the same. assert rdmol0_smiles == rdmol1_smiles + + +@pytest.mark.skipif( + has_antechamber is False or has_tleap is False, + reason="Requires AmberTools/antechamber and tLEaP to be installed.", +) +def test_acdoctor(): + """ + Test that parameterising negatively charged molecules works when acdoctor + is disabled. + """ + + # Load the molecule. + mol = BSS.IO.readMolecules(f"{url}/negative_charge.sdf")[0] + + # Make sure parameterisation fails when acdoctor is enabled. + with pytest.raises(BSS._Exceptions.ParameterisationError): + BSS.Parameters.gaff(mol).getMolecule() + + # Make sure parameterisation works when acdoctor is disabled. + mol = BSS.Parameters.gaff(mol, acdoctor=False).getMolecule()