Skip to content

Commit

Permalink
Updated copyright information.
Browse files Browse the repository at this point in the history
Refactored ENM code and tests to reflect ModelBase.
Added CG topology and trajectory files to test data.

Signed-off-by: Timothy Click <tcthepoet@yahoo.com>
  • Loading branch information
Timothy Click authored and Timothy Click committed Jan 18, 2019
1 parent 6292358 commit 2fa7b9d
Show file tree
Hide file tree
Showing 7 changed files with 1,857 additions and 202 deletions.
43 changes: 32 additions & 11 deletions src/fluctmatch/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding: utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
# -*- coding: utf-8 -*-
#
# fluctmatch --- https://github.com/tclick/python-fluctmatch
# Copyright (c) 2013-2017 The fluctmatch Development Team and contributors
# (see the file AUTHORS for the full list of names)
# python-fluctmatch -
# Copyright (c) 2019 Timothy H. Click, Ph.D.
#
# Released under the New BSD license.
# All rights reserved.
#
# Please cite your use of fluctmatch in published work:
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Timothy H. Click, Nixon Raj, and Jhih-Wei Chu.
# Calculation of Enzyme Fluctuograms from All-Atom Molecular Dynamics
# Simulation. Meth Enzymology. 578 (2016), 327-342,
# doi:10.1016/bs.mie.2016.05.024.
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of the author nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Timothy H. Click, Nixon Raj, and Jhih-Wei Chu.
# Simulation. Meth Enzymology. 578 (2016), 327-342,
# Calculation of Enzyme Fluctuograms from All-Atom Molecular Dynamics
# doi:10.1016/bs.mie.2016.05.024.

import logging

from .enm import Enm
Expand Down
221 changes: 122 additions & 99 deletions src/fluctmatch/models/enm.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
# -*- coding: utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
#
# fluctmatch --- https://github.com/tclick/python-fluctmatch
# Copyright (c) 2013-2017 The fluctmatch Development Team and contributors
# (see the file AUTHORS for the full list of names)
# python-fluctmatch -
# Copyright (c) 2019 Timothy H. Click, Ph.D.
#
# Released under the New BSD license.
# All rights reserved.
#
# Please cite your use of fluctmatch in published work:
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Timothy H. Click, Nixon Raj, and Jhih-Wei Chu.
# Calculation of Enzyme Fluctuograms from All-Atom Molecular Dynamics
# Simulation. Meth Enzymology. 578 (2016), 327-342,
# doi:10.1016/bs.mie.2016.05.024.
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
import numpy as np
from MDAnalysis.core import topologyattrs
from MDAnalysis.lib.distances import distance_array, self_capped_distance
from fluctmatch.fluctmatch import utils as fmutils
from fluctmatch.models.base import (
ModelBase,
rename_universe,
)
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of the author nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Timothy H. Click, Nixon Raj, and Jhih-Wei Chu.
# Simulation. Meth Enzymology. 578 (2016), 327-342,
# Calculation of Enzyme Fluctuograms from All-Atom Molecular Dynamics
# doi:10.1016/bs.mie.2016.05.024.
"""Class for elastic network model."""

from typing import List, Optional, Tuple

import MDAnalysis as mda
from MDAnalysis.core.topologyattrs import Atomtypes, Charges, Bonds
from MDAnalysis.lib import distances

from .base import ModelBase, rename_universe
from .selection import *


class Enm(ModelBase):
Expand All @@ -30,96 +52,97 @@ class Enm(ModelBase):
Determines the interactions between beads via distance cutoffs `rmin` and
`rmax`. The atoms and residues are also renamed to prevent name collision
when working with fluctuation matching.
"""
model = "ENM"
describe = "Elastic network model"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._rmin: float = kwargs.get("rmin", 0.)
self._rmax: float = kwargs.get("rmax", 10.)
self._initialize(*args, **kwargs)
Parameters
----------
extended : bool, optional
Renames the residues and atoms according to the extended CHARMM PSF
format. Standard CHARMM PSF limits the residue and atom names to four
characters, but the extended CHARMM PSF permits eight characters. The
residues and atoms are renamed according to the number of segments
(1: A, 2: B, etc.) and then the residue number or atom index number.
xplor : bool, optional
Assigns the atom type as either a numerical or an alphanumerical
designation. CHARMM normally assigns a numerical designation, but the
XPLOR version permits an alphanumerical designation with a maximum
size of 4. The numerical form corresponds to the atom index number plus
a factor of 100, and the alphanumerical form will be similar the
standard CHARMM atom name.
com : bool, optional
Calculates the bead coordinates using either the center of mass
(default) or center of geometry.
guess_angles : bool, optional
Once Universe has been created, attempt to guess the connectivity
between atoms. This will populate the .angles, .dihedrals, and
.impropers attributes of the Universe.
cutoff : float, optional
Used as a bond distance cutoff for an elastic network model; otherwise,
ignored.
min_cutoff : float, optional
Used as a minimum bond distance cutoff for an elastic network model;
otherwise, ignored.
charges : bool, optional
If True, keeps the original charges; otherwise, sets the charges to 0.
Attributes
----------
universe : :class:`~MDAnalysis.Universe`
The transformed universe
def __repr__(self) -> str:
message: str = f"<CG Universe with {self.atoms.n_atoms} beads"
try:
message += f" and {len(self._topology.bonds.values)} bonds"
except AttributeError as exc:
pass
finally:
message += ">"
return message

def _initialize(self, *args, **kwargs):
self.__dict__.update(self.atu.__dict__)

rename_universe(self)
charges: bool = kwargs.get("charges", False)
if not charges:
self._topology.add_TopologyAttr(
topologyattrs.Charges(np.zeros(self.atoms.n_atoms))
)
self._topology.add_TopologyAttr(
topologyattrs.Atomtypes(np.arange(self.atoms.n_atoms) + 1)
)
self._topology.add_TopologyAttr(topologyattrs.Angles([]))
self._topology.add_TopologyAttr(topologyattrs.Dihedrals([]))
self._topology.add_TopologyAttr(topologyattrs.Impropers([]))
self._generate_from_topology()

self._add_bonds()
if kwargs.get("guess_angles", False):
self._add_angles()
self._add_dihedrals()
self._add_impropers()
"""
model: str = "ENM"
describe: str = "Elastic network model"

def _add_bonds(self):
positions: np.ndarray = fmutils.AverageStructure(self.atu.atoms).run().result
pairs, _ = self_capped_distance(
positions, self._rmax, min_cutoff=self._rmin
)
bonds = topologyattrs.Bonds(np.unique(pairs, axis=0))
self._topology.add_TopologyAttr(bonds)
self._generate_from_topology()

@property
def rmin(self) -> float:
"""The minimum distance required to define a bond interaction.
Returns
-------
float
"""
return self._rmin
def __init__(self,
xplor: bool = True,
extended: bool = True,
com: bool = True,
guess_angles: bool = False,
cutoff: float = 10.0,
min_cutoff: Optional[float] = None,
charges: bool = False):
super().__init__(xplor, extended, com, guess_angles, cutoff)

self._min_cutoff: Optional[float] = min_cutoff
self._charges: bool = charges

@rmin.setter
def rmin(self, distance: float):
"""Set the minimum distance required for a bond definition.
def create_topology(self, universe: mda.Universe):
"""Deteremine the topology attributes and initialize the universe.
Parameters
----------
distance : float
Minimum distance between beads
universe : :class:`~MDAnalysis.Universe`
An all-atom universe
"""
self._rmin: float = distance
try:
self.universe = universe.copy()
except TypeError:
self.universe = universe

@property
def rmax(self) -> float:
"""The maximum distance required to define a bond interaction.
rename_universe(self.universe)

Returns
-------
float
"""
return self._rmax
if not self._charges:
charges = np.zeros(self.universe.atoms.n_atoms)
self.universe.add_TopologyAttr(Charges(charges))

@rmax.setter
def rmax(self, distance: float):
"""Set the maximum distance required for a bond definition.
atomtypes: np.ndarray = np.arange(self.universe.atoms.n_atoms) + 1
self.universe.add_TopologyAttr(Atomtypes(atomtypes))

Parameters
----------
distance : float
Maximum distance between beads
"""
self._rmax: float = distance
def add_trajectory(self, universe: mda.Universe):
pass

def _add_bonds(self):
positions: np.ndarray = np.zeros_like(self.universe.atoms.positions)
for _ in self.universe.trajectory:
positions += self.universe.atoms.positions
self.universe.trajectory.rewind()
positions /= self.universe.trajectory.n_frames

pairs, _ = distances.self_capped_distance(positions, self._cutoff,
min_cutoff=self._min_cutoff)
pairs: List[Tuple[int, int]] = [
tuple(_)
for _ in np.unique(pairs, axis=0)
]
bonds: Bonds = Bonds(pairs)
self.universe.add_TopologyAttr(bonds)
Binary file added tests/data/cg.dcd
Binary file not shown.
Loading

0 comments on commit 2fa7b9d

Please sign in to comment.