Skip to content

Commit

Permalink
setAtoms fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmkrieger committed Feb 17, 2021
1 parent 0d36833 commit 48b6e88
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 25 deletions.
4 changes: 2 additions & 2 deletions prody/ensemble/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def saveEnsemble(ensemble, filename=None, **kwargs):
'_padding', '_ionicStrength', '_force_field', '_tolerance',
'_maxIterations', '_sim', '_temp', '_t_steps', '_outlier',
'_mzscore', '_v1', '_parallel', '_idx_cg', '_n_cg', '_cycle',
'_time', '_targeted', '_tmdk'])
'_time', '_targeted', '_tmdk', '_topology', '_positions'])
if isinstance(ensemble, AdaptiveHybrid):
attr_list.extend(['_atomsB', '_defvecs', '_resetFmin', '_rmsds'])
atomsB = dict_['_atomsB']
Expand Down Expand Up @@ -168,7 +168,7 @@ def loadEnsemble(filename, **kwargs):
'_rmsd', '_n_gens', '_maxclust', '_threshold', '_sol',
'_sim', '_temp', '_t_steps', '_outlier', '_mzscore', '_v1',
'_parallel', '_idx_ca', '_n_ca', '_cycle', '_time', '_targeted',
'_tmdk']
'_tmdk', '_topology', '_positions']

for attr in attrs:
if attr in attr_dict.files:
Expand Down
23 changes: 13 additions & 10 deletions prody/hybrid/adaptive.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,9 @@ def _sample(self, conf, **kwargs):

return coordsets

def setAtoms(self, atomsA, atomsB, pH=7.0, **kwargs):
def setAtoms(self, atomsA, atomsB=None, pH=7.0, **kwargs):
aligned = kwargs.get('aligned', False)
if not aligned:
if not aligned and atomsB is not None:
T = calcTransformation(atomsA.ca, atomsB.ca, weights=atomsA.ca.getFlags("mapped"))
_ = applyTransformation(T, atomsA)

Expand All @@ -555,6 +555,9 @@ def setAtoms(self, atomsA, atomsB, pH=7.0, **kwargs):
self._atomsB = atomsB
else:
for i, atoms in enumerate([atomsA, atomsB]):
if i == 1 and atomsB is None:
break

atoms = atoms.select('not hetatm')

self._nuc = atoms.select('nucleotide')
Expand Down Expand Up @@ -628,17 +631,17 @@ def _fix(self, atoms, i):
self._topology = fixed.topology
self._positions = fixed.positions

def getAtomsA(self):

def getAtomsA(self, selected=True):
'Returns atoms for structure A (main atoms).'
return super(AdaptiveHybrid, self).getAtoms(selected)

return self._atoms

def getAtomsB(self):

def getAtomsB(self, selected=True):
'Returns atoms for structure B.'

return self._atomsB
if self._atomsB is None:
return None
if self._indices is None or not selected:
return self._atomsB
return self._atomsB[self._indices]

def getRMSDsB(self):
if self._confs is None or self._coords is None:
Expand Down
6 changes: 2 additions & 4 deletions prody/hybrid/clustenm.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ def __getitem__(self, index):

return super(ClustENM, self).__getitem__(index)

def getAtoms(self):

def getAtoms(self, selected=True):
'Returns atoms.'

return self._atoms
return super(ClustENM, self).getAtoms(selected)

def _isBuilt(self):

Expand Down
50 changes: 41 additions & 9 deletions prody/hybrid/hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@
from scipy.cluster.hierarchy import fcluster, linkage

from prody import LOGGER

from prody.dynamics.anm import ANM
from prody.dynamics.gnm import GNM, ZERO
from prody.dynamics.rtb import RTB
from prody.dynamics.imanm import imANM
from prody.dynamics.exanm import exANM
from prody.dynamics.editing import extendModel
from prody.dynamics.sampling import sampleModes
from prody.atomic import AtomGroup

from prody.atomic import AtomGroup, Atomic
from prody.measure import calcTransformation, applyTransformation, calcRMSD
from prody.ensemble import Ensemble
from prody.proteins import writePDB, parsePDB, writePDBStream, parsePDBStream
from prody.utilities import createStringIO, importLA, mad
from prody.proteins import writePDB, writePDBStream, parsePDBStream, EMDMAP
from prody.utilities import createStringIO, importLA, mad, getCoords

la = importLA()
norm = la.norm
Expand Down Expand Up @@ -115,17 +117,15 @@ def __getitem__(self, index):

return super(Hybrid, self).__getitem__(index)

def getAtoms(self):

def getAtoms(self, selected=True):
'Returns atoms.'

return self._atoms
return super(Hybrid, self).getAtoms(selected)

def _isBuilt(self):

return self._confs is not None

def setAtoms(self, atoms, pH=7.0):
def setAtoms(self, atoms):

'''
Sets atoms.
Expand All @@ -135,6 +135,7 @@ def setAtoms(self, atoms, pH=7.0):
:arg pH: pH based on which to select protonation states for adding missing hydrogens, default is 7.0.
:type pH: float
'''
super(Hybrid, self).setAtoms(atoms)

def getTitle(self):

Expand Down Expand Up @@ -164,7 +165,38 @@ def setTitle(self, title):
self._title = title

def _fix(self, atoms):
''''''

try:
from pdbfixer import PDBFixer
from simtk.openmm.app import PDBFile
except ImportError:
raise ImportError('Please install PDBFixer and OpenMM in order to use ClustENM.')

stream = createStringIO()
title = atoms.getTitle()
writePDBStream(stream, atoms)
stream.seek(0)
fixed = PDBFixer(pdbfile=stream)
stream.close()

fixed.missingResidues = {}
fixed.findNonstandardResidues()
fixed.replaceNonstandardResidues()
fixed.removeHeterogens(False)
fixed.findMissingAtoms()
fixed.addMissingAtoms()
fixed.addMissingHydrogens(self._ph)

stream = createStringIO()
PDBFile.writeFile(fixed.topology, fixed.positions,
stream, keepIds=True)
stream.seek(0)
self._atoms = parsePDBStream(stream)
self._atoms.setTitle(title)
stream.close()

self._topology = fixed.topology
self._positions = fixed.positions

def _prep_sim(self, coords, external_forces=[]):

Expand Down

0 comments on commit 48b6e88

Please sign in to comment.