Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/970
Browse files Browse the repository at this point in the history
  • Loading branch information
swails committed Sep 8, 2018
2 parents e94d8bd + 5b9837d commit d47f46f
Show file tree
Hide file tree
Showing 11 changed files with 2,954 additions and 58 deletions.
14 changes: 7 additions & 7 deletions devtools/ci/travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ if [ "$PYTHON_VERSION" = "pypy" ]; then
export PYENV_ROOT="${HOME}/.pyenv"
export PATH="${PYENV_ROOT}/bin:${PATH}"
eval "$(pyenv init -)"
pyenv install pypy-4.0.1
pyenv global pypy-4.0.1
pyenv install pypy2.7-6.0.0
pyenv global pypy2.7-6.0.0

pypy -m pip install nose pyflakes==1.0.0 nose-timer lxml
which pyflakes
pypy -m pip install --user git+https://bitbucket.org/pypy/numpy.git@pypy-4.0.1
pypy -m pip install numpy
else # Otherwise, CPython... go through conda
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
wget http://repo.continuum.io/miniconda/Miniconda-3.7.0-MacOSX-x86_64.sh -O miniconda.sh;
Expand Down Expand Up @@ -38,7 +38,7 @@ else # Otherwise, CPython... go through conda
conda install -y -n myenv rdkit==2015.09.1 -c omnia
conda install -y -n myenv boost==1.59.0 -c omnia
conda install -y -n myenv nglview -c bioconda
#conda install -y -n myenv ambertools=17.0 -c http://ambermd.org/downloads/ambertools/conda/
conda install -y -n myenv ambertools=18 -c http://ambermd.org/downloads/ambertools/conda/
conda install -y -n myenv networkx
conda install -y -n myenv lxml
else
Expand All @@ -48,9 +48,9 @@ else # Otherwise, CPython... go through conda
fi
source activate myenv
pip install pyflakes==1.0.0
#if [ -z "$MINIMAL_PACKAGES" ]; then
# pip uninstall parmed -y # from ambertools
#fi
if [ -z "$MINIMAL_PACKAGES" ]; then
pip uninstall parmed -y # from ambertools
fi

# DEBUG
conda list
Expand Down
2 changes: 1 addition & 1 deletion devtools/ci/travis/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ else
./run_scripts.sh
# Run nose under coverage, since that allows getting the full flexibility of
# the coverage package without sacrificing nose functionality
# test -z "$MINIMAL_PACKAGES" && export AMBERHOME=$HOME/miniconda/envs/myenv
test -z "$MINIMAL_PACKAGES" && export AMBERHOME=$HOME/miniconda/envs/myenv
coverage run --source=parmed --parallel-mode -m \
nose -vs --with-timer --timer-ok=5s --timer-warning=12s \
--timer-filter=warning,error .
Expand Down
33 changes: 28 additions & 5 deletions parmed/modeller/residue.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from parmed.structure import Structure
from parmed.topologyobjects import Atom, Bond, AtomList, TrackedList
from parmed.utils.six import iteritems
from parmed.exceptions import IncompatiblePatchError
from parmed.exceptions import IncompatiblePatchError, MoleculeError
import warnings

__all__ = ['PROTEIN', 'NUCLEIC', 'SOLVENT', 'UNKNOWN', 'ResidueTemplate',
Expand Down Expand Up @@ -463,8 +463,8 @@ def apply_patch(self, patch, precision=4):
try:
residue.delete_atom(atom_name)
modifications_made = True
except KeyError as e:
raise IncompatiblePatchError(str(e))
except (KeyError, MoleculeError) as e:
raise IncompatiblePatchError('Atom %s could not be deleted from the patched residue: atoms are %s (exception: %s)' % (atom_name, list(residue._map.keys()), str(e)))
# Add or replace atoms
for atom in patch.atoms:
if atom.name in residue:
Expand All @@ -486,8 +486,8 @@ def apply_patch(self, patch, precision=4):
# Add bond
residue.add_bond(atom1_name, atom2_name, order)
modifications_made = True
except IndexError as e:
raise IncompatiblePatchError('Bond %s-%s could not be added to patched residue: atoms are %s' % (atom1_name, atom2_name, list(residue._map.keys())))
except (IndexError, MoleculeError) as e:
raise IncompatiblePatchError('Bond %s-%s could not be added to patched residue: atoms are %s (exception: %s)' % (atom1_name, atom2_name, list(residue._map.keys()), str(e)))
# Delete impropers
for impr in patch.delete_impropers:
try:
Expand All @@ -512,6 +512,29 @@ def apply_patch(self, patch, precision=4):

return residue

def patch_is_compatible(self, patch):
"""Determine whether a specified patch is compatible with this residue.
Compatibility is determined by whether Residue.Template.apply_patch(patch) raises as
exception or not.
Parameters
----------
patch : PatchTemplate
The patch to be applied to this residue.
Returns
-------
is_compatible : bool
True if patch is compatible with the residue; False if not.
"""
try:
self.apply_patch(patch)
return True
except IncompatiblePatchError:
return False

def to_networkx(self):
""" Create a NetworkX graph of atoms and bonds
Expand Down
52 changes: 30 additions & 22 deletions parmed/openmm/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ..utils.six import add_metaclass, string_types, iteritems
from ..utils.six.moves import range
import warnings
from ..exceptions import ParameterWarning, IncompatiblePatchError
from ..exceptions import ParameterWarning
from itertools import product
from ..topologyobjects import (DihedralType, ImproperType)

Expand Down Expand Up @@ -114,6 +114,11 @@ def _remediate_residue_template(cls, params, residue):
residue : :class:`parmed.modeller.Residue`
The residue to remediate
Returns
-------
missing_parameters : bool
If True, the residue template is missing some parameters
"""
# Populate atomic numbers in residue template
# TODO: This can be removed if the parameter readers are guaranteed to populate this correctly
Expand Down Expand Up @@ -198,15 +203,21 @@ def from_parameterset(cls, params, copy=False, remediate_residues=True):
if hasattr(params, '_improper_key_map'):
new_params._improper_key_map = new_params._improper_key_map

# Add only ResidueTemplate instances (no ResidueTemplateContainers)
# Maintain original residue ordering
remediated_residues = list()
for name, residue in iteritems(params.residues):
if isinstance(residue, ResidueTemplate):
if (not remediate_residues) or cls._remediate_residue_template(new_params, residue):
if remediate_residues:
# Add only ResidueTemplate instances (no ResidueTemplateContainers)
# Maintain original residue ordering
remediated_residues = list()
for name, residue in iteritems(params.residues):
if isinstance(residue, ResidueTemplate):
# Don't discard the residue, but fix it if we need to
cls._remediate_residue_template(new_params, residue)
remediated_residues.append(residue)
for residue in remediated_residues:
new_params.residues[residue.name] = residue
for residue in remediated_residues:
new_params.residues[residue.name] = residue
else:
# Don't remediate residues; just copy
for name, residue in iteritems(params.residues):
new_params.residues[residue.name] = residue

# Only add unique patches
unique_patches = OrderedDict()
Expand Down Expand Up @@ -461,7 +472,7 @@ def _templhasher(residue):
hash_info = tuple()
# Sort tuples of atom properties by atom name
if len(residue.atoms) > 0:
hash_info += tuple(sorted( [(atom.name, atom.type, str(atom.charge)) for atom in residue.atoms] ))
hash_info += tuple(sorted( [(atom.type, str(atom.charge)) for atom in residue.atoms] ))
# Sort list of deleted atoms by atom name
if hasattr(residue, 'delete_atoms') and len(residue.delete_atoms) > 0:
hash_info += tuple(sorted([atom_name for atom_name in residue.delete_atoms]))
Expand Down Expand Up @@ -599,19 +610,16 @@ def _determine_valid_patch_combinations(self, skip_residues):
for residue in self.residues.values():
valid_patches_for_residue[residue.name] = list()

# Create list of residues to check compatibility against
residues = [ residue for residue in self.residues.values() if (residue not in skip_residues) ]

# Check patch compatibilities
for patch in self.patches.values():
for residue in self.residues.values():
if residue in skip_residues: continue
# Attempt to patch the residue.
try:
residue.apply_patch(patch)
except IncompatiblePatchError as e:
# Patching failed; continue to next patch
LOGGER.debug('%8s x %8s : %s', patch.name, residue.name, e)
continue

valid_residues_for_patch[patch.name].append(residue.name)
valid_patches_for_residue[residue.name].append(patch.name)
residue_compatibilities = [ residue.patch_is_compatible(patch) for residue in residues ]
for (residue, is_compatible) in zip(residues, residue_compatibilities):
if is_compatible:
valid_residues_for_patch[patch.name].append(residue.name)
valid_patches_for_residue[residue.name].append(patch.name)

return [valid_residues_for_patch, valid_patches_for_residue]

Expand Down
12 changes: 6 additions & 6 deletions test/files/aminont12.lib
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
"NTYR"
"NVAL"
!entry.ACE.unit.atoms table str name str type int typex int resx int flags int seq int elmnt dbl chg
"HH31" "HC" 0 1 131072 1 1 0.112300
"H1" "HC" 0 1 131072 1 1 0.112300
"CH3" "CT" 0 1 131072 2 6 -0.366200
"HH32" "HC" 0 1 131072 3 1 0.112300
"HH33" "HC" 0 1 131072 4 1 0.112300
"H2" "HC" 0 1 131072 3 1 0.112300
"H3" "HC" 0 1 131072 4 1 0.112300
"C" "C" 0 1 131072 5 6 0.597200
"O" "O" 0 1 131072 6 8 -0.567900
!entry.ACE.unit.atomspertinfo table str pname str ptype int ptypex int pelmnt dbl pchg
"HH31" "HC" 0 -1 0.0
"H1" "HC" 0 -1 0.0
"CH3" "CT" 0 -1 0.0
"HH32" "HC" 0 -1 0.0
"HH33" "HC" 0 -1 0.0
"H2" "HC" 0 -1 0.0
"H3" "HC" 0 -1 0.0
"C" "C" 0 -1 0.0
"O" "O" 0 -1 0.0
!entry.ACE.unit.boundbox array dbl
Expand Down
12 changes: 12 additions & 0 deletions test/files/ionsjc.pdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
REMARK 1 Test ions from frcmod.ionsjc_tip3p with complete parameters
CRYST1 22.771 23.117 23.235 90.00 90.00 90.00 P 1 1
HETATM 1 BR BR A 1 10.569 16.024 -1.115 1.00 0.00 Br
HETATM 2 CL CL A 2 8.569 0.024 7.885 1.00 0.00 Cl
HETATM 3 CS CS A 3 2.275 20.986 22.847 1.00 0.00 Cs
HETATM 4 F F A 4 -0.725 20.986 18.847 1.00 0.00 F
HETATM 5 I IOD A 5 18.711 21.460 16.321 1.00 0.00 I
HETATM 6 K K A 6 20.711 6.460 14.321 1.00 0.00 K
HETATM 7 LI PI A 7 -4.599 21.150 18.011 1.00 0.00 Li
HETATM 8 NA NA A 8 -0.599 8.150 4.011 1.00 0.00 Na
HETATM 9 RB RB A 9 23.768 5.391 15.252 1.00 0.00 Rb
END
Loading

0 comments on commit d47f46f

Please sign in to comment.