Skip to content

Commit

Permalink
Merge pull request #136 from martimunicoy/devel
Browse files Browse the repository at this point in the history
1.2.1 Release
  • Loading branch information
martimunicoy committed Apr 7, 2021
2 parents a81633a + de108f4 commit 31a1487
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 31 deletions.
8 changes: 4 additions & 4 deletions docs/forcefield.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _forcefield ::
.. _forcefield :

Forcefield methods
==============
==================

This module defines the different force fields that are available
in `peleffy` to parameterize molecules for PELE.
Expand All @@ -13,8 +13,8 @@ Primary objects

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst
:toctree: api/autogenerated

OpenForceField
OPLS2005ForceField
Expand All @@ -26,8 +26,8 @@ Secondary objects

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst
:toctree: api/autogenerated

calculators.Am1bccCalculator
calculators.GasteigerCalculator
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Installation
Installing via `conda`
======================
The more straightforward way to install `peleffy` along with the required
dependencies is through the `conda <http://www.continuum.io/blog/conda>`_
dependencies is through the `conda <https://docs.conda.io/en/latest/>`_
package manager.

First, you need to install the
Expand Down
20 changes: 20 additions & 0 deletions docs/releasehistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ Releases follow the ``major.minor.micro`` scheme recommended by `PEP440 <https:/
* ``minor`` increments add features but do not break API compatibility
* ``micro`` increments represent bugfix releases or improvements in documentation


1.2.1 - API Documentation and improvements
------------------------------------------

This is a micro release of peleffy that includes and new method to load parameters from a JSON file and solves different bugs in the documentation and the OPLS parametrization.

New features
""""""""""""
- `PR #131 <https://github.com/martimunicoy/peleffy/pull/131>`_: New method to load parameters from a JSON file.

Tests added
"""""""""""
- `PR #131 <https://github.com/martimunicoy/peleffy/pull/131>`_: Adds tests to validate the new method to load parameters from a JSON file.

Bugfixes
""""""""
- `PR #129 <https://github.com/martimunicoy/peleffy/pull/129>`_: Some format errors in the API documentation are fixed. Links to the PELE documentation are updated.
- `PR #134 <https://github.com/martimunicoy/peleffy/pull/134>`_: Fixes bug when parsing the parameters of the ligand when OPLS is used to parameterize.


1.2.0 - New tools for parameters and templates
----------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions docs/solvent.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _solvent ::
.. _solvent :

Solvent models
==============
Expand All @@ -13,8 +13,8 @@ Primary objects

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst
:toctree: api/autogenerated

OBC2
OPLSOBC
Expand All @@ -25,7 +25,7 @@ Secondary objects

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst
:toctree: api/autogenerated

OBC1
6 changes: 3 additions & 3 deletions docs/template.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _template ::
.. _template :

Template handlers
=================
Expand All @@ -12,8 +12,8 @@ Primary objects

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst
:toctree: api/autogenerated

Impact

Expand All @@ -23,8 +23,8 @@ Secondary objects

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst
:toctree: api/autogenerated

impact.WritableWrapper
impact.WritableAtom
Expand Down
6 changes: 3 additions & 3 deletions docs/topology.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _topology ::
.. _topology :

Topology representations
========================
Expand All @@ -14,8 +14,8 @@ Primary objects

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst
:toctree: api/autogenerated

Molecule
Topology
Expand All @@ -26,8 +26,8 @@ Secondary objects

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst
:toctree: api/autogenerated

Atom
Bond
Expand Down
6 changes: 4 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Generate PELE parameter files

The main purpose of `peleffy` is to build the parameter files for PELE. Basically, PELE requires two files for each non-standard residue found in the system:

- `IMPACT template <https://eapm-bsc.github.io/PELE-repo/fileFormats.html#impact-template-file-format>`_: a file containing the atom types and parameters of the ligand. Its job is to link each atom with the corresponding parameters using PDB atom names. Thus, PDB atom names in the input PDB file must match with the expected PDB atom names in the Impact file. This file intrinsically contains the information about the topology and connectivity of each residue.
- `IMPACT template <https://nostrumbiodiscovery.github.io/pele_docs/fileFormats.html#sec-fileformats-impact>`_: a file containing the atom types and parameters of the ligand. Its job is to link each atom with the corresponding parameters using PDB atom names. Thus, PDB atom names in the input PDB file must match with the expected PDB atom names in the Impact file. This file intrinsically contains the information about the topology and connectivity of each residue.

- `Rotamer library <https://eapm-bsc.github.io/PELE-repo/fileFormats.html#ligand-rotamer-library-file>`_: a file containing the branches that can rotate with respect to a central atomic core. Each branch consists in a set of consecutive rotatable bonds.
- `Rotamer library <https://nostrumbiodiscovery.github.io/pele_docs/fileFormats.html#sec-fileformats-ligandrotamers>`_: a file containing the branches that can rotate with respect to a central atomic core. Each branch consists in a set of consecutive rotatable bonds.

Besides, a third file with the `Solvent parameters` might be required when employing the OBC implicit solvent.

Expand Down Expand Up @@ -102,6 +102,8 @@ arguments. To obtain the full list of flags you can type:
hierarchy
-c NAME, --charge_method NAME
The name of the method to use to compute charges
--charges_from_file PATH
The path to the file with charges
--include_terminal_rotamers
Not exclude terminal rotamers when building the
rotamer library
Expand Down
131 changes: 116 additions & 15 deletions peleffy/forcefield/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,107 @@ def to_json(self, output_path):
json.dump(convert_all_quantities_to_string(self), f,
indent=4, sort_keys=True)

def from_json(self, input_path):
"""
It loads a json file containing the parameters into the parameter
wrapper.
Parameters
----------
input_path : str
The path to the json file to load the parameters from
Returns
-------
self : a BaseParameterWrapper object
The resulting parameters wrapper
"""
import json
def correct_type(label, value):
"""
It converts the parameters loaded from the JSON file into the
expected data type in the parameter wrapper.
Parameters
----------
label : str
Label for the parameters
value : list
Set of parameters
Returns
-------
correct_value : list
Set of paramaeters with the expected data type
"""
import simtk.unit
from peleffy.utils import string_to_quantity

# Dictionary relating parameters key with the expected data type
dict_units = {
'alphas': float, 'gammas': float,
'charges': simtk.unit.quantity.Quantity,
'sigmas' : 'list_Quantity', 'epsilons' : 'list_Quantity',
'SGB_radii' : 'list_Quantity','vdW_radii' : 'list_Quantity',
'angles': dict, 'bonds': dict, 'impropers': dict,
'propers': dict, 'GBSA_radii': 'list_Quantity',
'GBSA_scales': 'list_Quantity',
'atom_names': str, 'atom_types' : str
}

# Skip data type transformation if the list is empty or None values
if value == [None,] * len(value):
return value
if value == []:
return None

# Perform data type transformation, if needed
else:
if dict_units[label] is str:
correct_value = value

if dict_units[label] is float:
correct_value = [float(v) if not v is None else v
for v in value]

if dict_units[label] is simtk.unit.quantity.Quantity:
correct_value = string_to_quantity(value)
return correct_value

if dict_units[label] == 'list_Quantity':
correct_value = \
[unit.Quantity(value=string_to_quantity(v)._value,
unit=string_to_quantity(v).unit)
for v in value]

if dict_units[label] is dict:
correct_value = []
for element in value:
correct_dict = dict()
for k,v in element.items():
if 'idx' in k:
correct_dict[k] = int(v)
else:
try:
correct_dict[k] = unit.Quantity(
value=string_to_quantity(v)._value,
unit=string_to_quantity(v).unit)
except:
correct_dict[k] = v
correct_value.append(correct_dict)
return correct_value

# Load the dict from the JSON file
with open(input_path) as f:
data = json.load(f)

# Correct the data type format and fetch the BaseParameterWrapper
for key, value in data.items():
value_correct = correct_type(key, value)
if not value_correct is None:
self.add_parameters(key, value_correct)
return self

@property
def atom_iterator(self):
"""
Expand Down Expand Up @@ -299,7 +400,7 @@ def from_impact_template(molecule, impact_template_path):
>>> from peleffy.forcefield.parameters import \
OpenForceFieldParametersWrapper
>>> wrapper_off = OpenForceFieldParameterWrapper()
>>> wrapper_off = OpenForceFieldParametersWrapper()
>>> parameters = wrapper_off.from_impact_template(
molecule, impact_template_path)
Expand Down Expand Up @@ -952,7 +1053,7 @@ def from_ffld_output(molecule, ffld_output):
assert len(fields) > 7, 'Unexpected number of fields ' \
+ 'found at line {}'.format(line)

name_to_index[line[0:4]] = len(name_to_index)
name_to_index[line[0:8]] = len(name_to_index)

params['atom_types'].append(fields[3])
params['charges'].append(
Expand All @@ -971,8 +1072,8 @@ def from_ffld_output(molecule, ffld_output):
+ 'found at line {}'.format(line)

params['bonds'].append(
{'atom1_idx': name_to_index[line[0:4]],
'atom2_idx': name_to_index[line[8:12]],
{'atom1_idx': name_to_index[line[0:8]],
'atom2_idx': name_to_index[line[8:16]],
'spring_constant': unit.Quantity(
float(fields[2]), unit.kilocalorie
/ (unit.angstrom ** 2 * unit.mole)),
Expand All @@ -986,9 +1087,9 @@ def from_ffld_output(molecule, ffld_output):
+ 'found at line {}'.format(line)

params['angles'].append(
{'atom1_idx': name_to_index[line[0:4]],
'atom2_idx': name_to_index[line[8:12]],
'atom3_idx': name_to_index[line[16:20]],
{'atom1_idx': name_to_index[line[0:8]],
'atom2_idx': name_to_index[line[8:16]],
'atom3_idx': name_to_index[line[16:24]],
'spring_constant': unit.Quantity(
float(fields[3]), unit.kilocalorie
/ (unit.radian ** 2 * unit.mole)),
Expand All @@ -1001,10 +1102,10 @@ def from_ffld_output(molecule, ffld_output):
assert len(fields) > 9, 'Unexpected number of fields ' \
+ 'found at line {}'.format(line)

atom1_idx = name_to_index[line[0:4]]
atom2_idx = name_to_index[line[8:12]]
atom3_idx = name_to_index[line[16:20]]
atom4_idx = name_to_index[line[24:28]]
atom1_idx = name_to_index[line[0:8]]
atom2_idx = name_to_index[line[8:16]]
atom3_idx = name_to_index[line[16:24]]
atom4_idx = name_to_index[line[24:32]]

for k, periodicity, phase in zip(
fields[4:8], [1, 2, 3, 4],
Expand Down Expand Up @@ -1051,10 +1152,10 @@ def from_ffld_output(molecule, ffld_output):
unit.kilocalorie / unit.mole)

params['impropers'].append(
{'atom1_idx': name_to_index[line[0:4]],
'atom2_idx': name_to_index[line[8:12]],
'atom3_idx': name_to_index[line[16:20]],
'atom4_idx': name_to_index[line[24:28]],
{'atom1_idx': name_to_index[line[0:8]],
'atom2_idx': name_to_index[line[8:16]],
'atom3_idx': name_to_index[line[16:24]],
'atom4_idx': name_to_index[line[24:32]],
'periodicity': 2,
'phase': unit.Quantity(180.0, unit.degree),
'k': k / 2.0, # PELE works with half of Schrodinger's force constant
Expand Down
Loading

0 comments on commit 31a1487

Please sign in to comment.