Skip to content

Commit

Permalink
more changes to adaptive ANM but it still does not work for selections
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmkrieger committed Aug 14, 2019
1 parent 6774197 commit 3a3012a
Showing 1 changed file with 50 additions and 36 deletions.
86 changes: 50 additions & 36 deletions prody/dynamics/adaptive.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from prody.ensemble import PDBEnsemble, Ensemble
from .mode import Vector
from .anm import ANM
from .functions import reduceModel
from .functions import reduceModel, calcENM
from .modeset import ModeSet
from prody.trajectory import writeDCD
from prody.proteins import writePDB, mapOntoChain, mapChainByChain
Expand All @@ -25,10 +25,8 @@

class AdaptiveANM(object):
def __init__(self, structA, structB, **kwargs):
self.structA = structA.copy()
self.structB = structB.copy()
self.origA = structA
self.origB = structB
self.structA = structA
self.structB = structB

self.cutoff = kwargs.pop('cutoff', 15.0) # default cutoff for ANM.buildHessian
self.gamma = kwargs.pop('gamma', 1.0) # default gamma for ANM.buildHessian
Expand All @@ -37,6 +35,22 @@ def __init__(self, structA, structB, **kwargs):
self.alignSelA = kwargs.get('alignSelA', self.alignSel)
self.alignSelB = kwargs.get('alignSelB', self.alignSel)

self.reduceSel = kwargs.pop('reduceSel', None)
self.reduceSelA = kwargs.get('reduceSelA', self.reduceSel)
self.reduceSelB = kwargs.get('reduceSelB', self.reduceSel)

if self.alignSelA is None:
self.alignSelA = self.reduceSelA

if self.alignSelB is None:
self.alignSelB = self.reduceSelB

if self.reduceSelA is None:
self.reduceSelA = self.alignSelA

if self.reduceSelB is None:
self.reduceSelB = self.alignSelB

if self.alignSelA is None:
structA_sel = self.structA
else:
Expand All @@ -63,28 +77,25 @@ def __init__(self, structA, structB, **kwargs):
_, T = superpose(structA_sel, structB_amap)
structA = applyTransformation(T, structA)

self.reduceSel = kwargs.pop('reduceSel', None)
#self.reduceSelA = kwargs.get('reduceSelA', self.reduceSel)
#self.reduceSelB = kwargs.get('reduceSelB', self.reduceSel)

rmsd = calcRMSD(structA_sel, structB_amap)
self.rmsds = [rmsd]
self.dList = []
self.numSteps = 0

self.anmA = kwargs.get('anmA', None)
if self.anmA is None:
self.anmA = ANM(structA)
self.anmListA = []
else:
self.anmListA = [self.anmA]
self.trim = kwargs.pop('trim', 'slice')

self.anmB = kwargs.get('anmB', None)
if self.anmB is None:
self.anmB = ANM(structB)
self.anmListB = []
self.anmA = kwargs.pop('anmA', None)
self.anmB = kwargs.pop('anmB', None)

if self.anmA is not None:
self.anmListA = [self.anmA]
else:
self.anmListA = []

if self.anmB is not None:
self.anmListB = [self.anmB]
else:
self.anmListB = []

self.n_modes = 20
self.numModesList = []
Expand Down Expand Up @@ -134,6 +145,20 @@ def runStep(self, structA=None, structB=None, **kwargs):
alignSelB = kwargs.pop('alignSel', self.alignSelB)

reduceSel = kwargs.pop('reduceSel', self.reduceSel)
reduceSelA = kwargs.pop('reduceSelA', self.reduceSelA)
reduceSelB = kwargs.pop('reduceSelB', self.reduceSelB)

if reduceSelA is None:
reduceSelA = reduceSel

if reduceSelB is None:
reduceSelB = reduceSel

if alignSelA is None:
alignSelA = reduceSelA

if alignSelB is None:
alignSelB = reduceSelB

Fmin = kwargs.get('Fmin', self.Fmin)

Expand Down Expand Up @@ -168,20 +193,11 @@ def runStep(self, structA=None, structB=None, **kwargs):
_, T = superpose(structA_sel, structB_amap)
structA = applyTransformation(T, structA)

anmA = kwargs.get('anmA', self.anmA)

self.cutoff = kwargs.pop('cutoff', self.cutoff)
self.gamma = kwargs.pop('gamma', self.gamma)

anmA.buildHessian(structA, cutoff=self.cutoff, gamma=self.gamma, **kwargs)
trim = kwargs.pop('trim', self.trim)
anmA, selA = calcENM(structA, reduceSelA, trim=trim, **kwargs)

if reduceSel:
anmA, selA = reduceModel(anmA, structA, reduceSel)

anmA.calcModes(self.n_modes, **kwargs)

coordsA = structA.getCoords()
coordsB = structB.getCoords()
coordsA = structA.select(reduceSelA).getCoords()
coordsB = structB.select(reduceSelB).getCoords()

defvec = coordsB - coordsA
d = defvec.flatten()
Expand Down Expand Up @@ -274,8 +290,6 @@ def runStep(self, structA=None, structB=None, **kwargs):
self.ensembleB.addCoordset(new_coordsA)
self.whichModesB.append(modesetA[modesCrossingFmin])



rmsd = calcRMSD(new_coordsA, coordsB)

LOGGER.info('Current RMSD is {:4.3f}\n'.format(rmsd))
Expand Down Expand Up @@ -341,7 +355,7 @@ def runManyStepsAlternating(self, n_steps, **kwargs):
break

ensemble = Ensemble('combined trajectory')
ensemble.setAtoms(self.origA)
ensemble.setAtoms(self.structA)
for coordset in self.ensembleA.getCoordsets():
ensemble.addCoordset(coordset)
for coordset in reversed(self.ensembleB.getCoordsets()):
Expand Down Expand Up @@ -378,7 +392,7 @@ def runManyStepsFurthestEachWay(self, n_steps, **kwargs):
break

ensemble = Ensemble('combined trajectory')
ensemble.setAtoms(self.origA)
ensemble.setAtoms(self.structA)
for coordset in self.ensembleA.getCoordsets():
ensemble.addCoordset(coordset)
for coordset in reversed(self.ensembleB.getCoordsets()):
Expand Down

0 comments on commit 3a3012a

Please sign in to comment.