Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
50180d7
Changements setup.py Benoist
glamothe Apr 5, 2016
c6dda8c
Merge branch 'develop' of /ibpc/minos/lamothe/monptools into develop
glamothe Apr 5, 2016
7e29d68
Modified C++ code: created Mcop class and AttractMcop subclass (repla…
glamothe Apr 5, 2016
6863650
Created bindings for Mcop class and AttractMcop subclass.
glamothe Apr 5, 2016
9ad5c5d
Added no argument constructor to attractrigidbody.pyx
glamothe Apr 5, 2016
a2b69ac
Fixed cython constructor for atomselection.
glamothe Apr 5, 2016
1fc8b14
Modified reduce.py to accept mcop option.
glamothe Apr 5, 2016
adc12ba
Created python functions useful for reduce's mcop option. Functions a…
glamothe Apr 5, 2016
9e8ea0f
Modified the python reduce file of all forcefields to code the mcop o…
glamothe Apr 5, 2016
14534a0
Created Mcoprigid C++ constructor that takes a multicopy pdb filename…
glamothe Apr 11, 2016
270e7f6
Changed Mcop::isNewModel to static so Mcoprigid::ReadMcoprigidPDB can…
glamothe Apr 11, 2016
a34b0ea
Merge github.com:ptools/ptools into feature/attract_read_multicopy_pdb
glamothe Apr 11, 2016
e7b92bd
Created Mcoprigid constructors in binding interface mcopff.pyx : Mcop…
glamothe Apr 11, 2016
a71887c
Created déallocator of the Mcoprigid class in binding interface mcopf…
glamothe Apr 11, 2016
1727a74
Created C++ functions for Mcoprigid class: getCore(), getRegion(i), s…
glamothe Apr 11, 2016
b32cf1c
Fixed cython Mcoprigig constructor compilation error. Changed Ptools …
glamothe Apr 12, 2016
e968a97
Fixed compilation of getCore and getRegion in Mcoprigid class (mcopff…
glamothe Apr 12, 2016
df8341d
Fixed C++ bugs in ReadMcoprigidPDB (mcopff.cpp)
glamothe Apr 12, 2016
c96439d
Created __len__ function for Mcoprigid class (mcopff.pyx)
glamothe Apr 12, 2016
93b1131
Added --mcop to option parser in attract.py.
glamothe Apr 12, 2016
6eeb945
Removed debug prints from ReadMcoprigidPDB in mcopff.cpp
glamothe Apr 12, 2016
8ef34cf
Minor comment mod
glamothe Apr 12, 2016
80fe3bf
In attract.py, when loading ligand file (line 293), if --mcop option,…
glamothe Apr 12, 2016
14265ea
Changed rec to Mcoprgid instead of lig (attract.py).
glamothe Apr 14, 2016
1ce5d40
Added getCore function to binding interface of Mcoprigid class.
glamothe Apr 18, 2016
e30d41f
In attract.py import lig as Mcoprigid if mcop option.
glamothe Apr 18, 2016
fdf4c87
Added iniWeights function that in used in constructor of Mcoprigid cl…
glamothe Apr 18, 2016
ab36ac3
Added mcopff variable of type McopForceField in attract.py, but still…
glamothe Apr 21, 2016
c803661
Added McopForceField class to binding interface.
glamothe Apr 21, 2016
e3330b3
Merge https://github.com/ptools/ptools into feature/attract_read_mult…
glamothe Apr 21, 2016
9eb0b16
Override setTranslation and setRotation in Mcoprigid class to apply i…
glamothe Apr 21, 2016
cfae988
In attract.py, applied setLigand and setReceptor to mcopff variable (…
glamothe Apr 21, 2016
810b264
In attract.py, if mcop option, create Lbfgs minimizer from mcopff obj…
glamothe Apr 21, 2016
508fd13
Added Mcoprigid's getWeights() to binding interface.
glamothe Apr 21, 2016
bab931b
Created C++ functions denormalize_weights() and normalize_weights() i…
glamothe Apr 21, 2016
3822c7f
Created C++ functions denormalize_weights() and normalize_weights() i…
glamothe Apr 21, 2016
8f23efd
Added C++ function getWeights(), normalize_weights(), and denormalize…
glamothe Apr 21, 2016
1abd458
Defined overriden ProblemSize() function in McopForceField.
glamothe Apr 22, 2016
44c0f9e
Added normalize_weights() and denormalize_weights() in Lbfgs class. T…
glamothe Apr 22, 2016
8b82413
Before each minimization step, denormalize weights (call denormalize_…
glamothe Apr 22, 2016
e582530
Fixed lbjgs_interface.cpp compilation error in denormalize and normal…
glamothe Apr 25, 2016
050dc7d
Changed McopForceField's Function() (calculates energies) to use deno…
glamothe Apr 25, 2016
01a1dfa
Made McopForceField's Function() more generic in case there is no rot…
glamothe Apr 25, 2016
588198a
Fix error in McopForceField's Function(): put force calculations in s…
glamothe Apr 25, 2016
4da6b16
Coded McopForceField's Derivatives() : Rotation/Translation but not w…
glamothe Apr 25, 2016
d41fbd7
Added _mcop_E attribute to McopForceField. Coded McopForceField's Der…
glamothe Apr 25, 2016
5b218f1
Fixed McopForceField's Derivatives() and can now compile.
glamothe Apr 26, 2016
3b69870
In McopForcefield's Function(), absolute changes (instead of relative…
glamothe Apr 26, 2016
d5eb4c7
Added FindCenter() to McopRigid class and added it to binding interface.
glamothe Apr 26, 2016
db4a218
Added if statement in attract.py: if mcop option, ligand is lig.getCo…
glamothe Apr 26, 2016
60a1768
Fixed Mcoprigid's FindCenter() in binding interface.
glamothe Apr 26, 2016
e12bd42
Added Mcoprigid's setTranslation(), setRotation(), Translate(), and A…
glamothe Apr 26, 2016
cc1ecb7
Typo fix.
glamothe Apr 26, 2016
4429c7d
Added McopForceField's setReceptor() and setLigand() to binding inter…
glamothe Apr 26, 2016
6247924
typo fix
glamothe Apr 26, 2016
b3598eb
In binding interface, made lbfgs class's ff attribute of type ForceFi…
glamothe Apr 26, 2016
6c1363b
comment typo fix
glamothe Apr 26, 2016
b416178
In Mcoprigid::getWeights : get weights from _receptor, not _centered_…
glamothe Apr 27, 2016
998334e
Added space for nicer formatting
glamothe Apr 27, 2016
535b7bd
Made AddAtom() in Rigidody virtual. Override AdAtom() in AttractRigid…
glamothe Apr 27, 2016
037ffc6
typo fix
glamothe Apr 28, 2016
7ad7c63
nothing
glamothe Apr 28, 2016
e183a22
nothing
glamothe Apr 28, 2016
3dd3ab3
Bugfix: added initialization of m_forces in AttractRigidbody's AddAto…
glamothe Apr 28, 2016
a881c8c
Bugfix: Coded ini_energies() and applied it to McopForceField's setRe…
glamothe Apr 28, 2016
e05418e
Coded CalcEnergy() in McopForceField, added it to binding interface a…
glamothe Apr 29, 2016
b93f3ee
Added getWeights() in Lbfgs class. It calls its equivalent funciton i…
glamothe Apr 29, 2016
6b110c1
Added _buffer_weights and _buffer_denorm_weights attributes to McopFo…
glamothe Apr 29, 2016
42432f7
Coded update_weights() in Mcoprigid class. Coded checkTranslation() a…
glamothe Apr 29, 2016
2fa0dbb
Implemented updateWeights() in attract.py. Coded and implemented prin…
glamothe Apr 29, 2016
62329da
Bugfix: for loops with uint i missing afectation: in denormalize_weig…
glamothe Apr 29, 2016
5382e97
Did math fixes in McopForceField's Derivatives() and Function(). Igno…
glamothe May 2, 2016
82c7601
Fixed reference RMSD calculation for mcop option in attract.py
glamothe May 2, 2016
59b1c12
Math fix in Derivatives()
glamothe May 2, 2016
4f0f7ec
Attempt at fixing buffer weights problem.
glamothe May 3, 2016
ab65a14
Normalization/denormalization fix in McopForceField's Funciton().
glamothe May 9, 2016
d67e145
reduce translation forces
glamothe May 23, 2016
18a9cd2
keep tranlation id from translation file
glamothe May 23, 2016
8e839b8
debug prints commented
glamothe Jun 9, 2016
5e15281
debug prints commented
glamothe Jun 9, 2016
c82b679
remove debug prints
glamothe Jun 9, 2016
f18bae2
Add weight evolution in single option and fix bug: minimize with cent…
glamothe Jun 9, 2016
e469912
Fixed bug: polymorphic CalcEnergy() function in mcopff binding interf…
glamothe Jun 9, 2016
5570b90
No longer need Scorpion_Lbfgs.pyx because same as Lbfgs.pyx
glamothe Jun 9, 2016
1c823dd
Added --trans and --rot options to attract.py which allows us to do a…
glamothe Jun 13, 2016
81d192d
Remove unused variables.
glamothe Jun 29, 2016
fd67fbf
remove pow
glamothe Jun 29, 2016
b13f630
Remove pow calls. Switch corefore copyforce arguments in nonbon8_forc…
glamothe Jun 29, 2016
b15d37a
Extreme weight discrimination at last minimization
glamothe Jul 3, 2016
8210494
Removed minimization approach using denormalized weights. Implemented…
glamothe Jul 20, 2016
69af583
Made arguments in Function() const again. (const was removed for a test)
glamothe Jul 20, 2016
19d2bb5
Modified weight variation output
glamothe Jul 21, 2016
b504c21
change beta and remove comments
glamothe Jul 26, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 120 additions & 48 deletions PyAttract/attract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import bz2 #for compression of Ligand and receptor data
import base64 #compressed ligand and receptor as base64 strings



def surreal(i):
return i

Expand All @@ -33,6 +31,17 @@ def PrintVect(vect):
print vect[i], " | ",
print ''

def printWeights(w, e):
print "### WEIGHTS BEGIN"
for region in xrange(0, len(w)):
sum = 0
print "### Start Region %d" %(region+1)
for copy in xrange(0, len(w[region])):
sum += w[region][copy]
print "WEIGHT REGION %d COPY %d = %f (Energy = %f)" %(region+1, copy+1, w[region][copy], e[region][copy])
print "WEIGHT SUM OF WEIGHTS = %f" %sum
print "### End Region %d" %(region+1)
print "### WEIGHTS END"


class Rotation:
Expand Down Expand Up @@ -85,6 +94,9 @@ def __init__(self):
def __iter__(self):
return self._rot.__iter__()

def __getitem__(self, i):
return self._rot.__getitem__(i)



class Translation:
Expand Down Expand Up @@ -185,19 +197,18 @@ def checkFile(name, comment):
## MAIN ATTRACT PROGRAM #
###########################
from optparse import OptionParser
parser = OptionParser(usage="%prog -r receptor_file -l ligand_file [-h] [-s] [-t] [--ref]")
parser = OptionParser(usage="%prog -r receptor_file -l ligand_file [-h] [-s] [-trans] [-rot] [--ref]")
parser.add_option("-r", "--receptor", action="store", type="string", dest="receptor_name", help="name of the receptor file")
parser.add_option("-l", "--ligand", action="store", type="string", dest="ligand_name", help="name of the ligand file")
parser.add_option("-s", "--single", action="store_true", dest="single", default=False, help="single minimization mode")
parser.add_option("--ref", action="store", type="string", dest="reffile", help="reference ligand for rmsd" )
parser.add_option("-t", "--translation", action="store", type="int", dest="transnb", help="translation number (distributed mode) starting from 0 for the first one!")
parser.add_option("--start1", action="store_true", default=False, dest="start1", help="(only useful with -t), use 1 for the first translation point")
parser.add_option("--trans", "--translation", action="store", type="int", dest="transnb", help="translation number (distributed mode).")
parser.add_option("--rot", "--rotation", action="store", type="int", dest="rotnb", help="rotation number (distributed mode).")
parser.add_option("--start1", action="store_true", default=False, dest="start1", help="(only useful with -trans), use 1 for the first translation point")
parser.add_option("--mcop", action="store_true", default=False, dest="regions", help="mcop option for multi-copy rigid-body docking")
(options, args) = parser.parse_args()


#receptor_name=args[0]
#ligand_name=args[1]

print """
**********************************************************************
** **
Expand All @@ -213,7 +224,7 @@ def checkFile(name, comment):

#locale.setlocale(locale.LC_ALL, 'fr_FR')
time_start = datetime.datetime.now()
#print now,"(",now.strftime("%A %B %d %Y, %H:%M"),")"

print "Start time:", time_start


Expand Down Expand Up @@ -248,7 +259,7 @@ def check_ffversion(reduced):
allff_specs = {
'SCORPION': {'ff_file': 'scorpion.par',
'ff_class': ScorpionForceField,
'minimizer_class': ScorpionLbfgs
'minimizer_class': Lbfgs
},

'ATTRACT1': {'ff_file': 'aminon.par',
Expand Down Expand Up @@ -287,22 +298,30 @@ def check_ffversion(reduced):




#load receptor and ligand:
rec=Rigidbody(options.receptor_name)
lig=Rigidbody(options.ligand_name)
rec=AttractRigidbody(rec)
lig=AttractRigidbody(lig)
if options.regions:
rec=Mcoprigid(options.receptor_name)
core=AttractRigidbody(options.ligand_name)
lig=Mcoprigid()
lig.setCore(core)
else:
rec=Rigidbody(options.receptor_name)
rec=AttractRigidbody(rec)
lig=Rigidbody(options.ligand_name)
lig=AttractRigidbody(lig)

print "Reading receptor (fixed): %s with %d particules" %( options.receptor_name, len(rec) )
print "Reading ligand (mobile): %s with %d particules" %( options.ligand_name, len(lig) )

if (options.single and options.transnb):
parser.error("options -s and -t are mutually exclusive")
if (options.single and (options.transnb or options.rotnb)):
parser.error("options -s and -trans/rot are mutually exclusive")

# save all minimization variables in trajectory file
trjname = "minimization.trj"
if (options.single):
if (options.single or (options.transnb and options.rotnb)):
ftraj = open(trjname, "w")
if(options.regions):
weight_variation = open("weight_variation.dat", "w")

if (options.reffile):
checkFile(options.reffile, "")
Expand All @@ -315,6 +334,15 @@ def check_ffversion(reduced):
else:
Rmsd_alias = rmsdca

firstr = 0
ff = open("translation.dat",'r')
for line in ff:
if "ATOM" in line:
spl = line.split()
firstr = int(spl[1])-1
break
ff.close()

if (not options.single):
#systematic docking with default translations and rotations
# check for rotation.dat and translation.dat
Expand All @@ -331,43 +359,44 @@ def check_ffversion(reduced):


printFiles=True
# option -t used: define the selected translation
# option -trans used: define the selected translation
transnb=0
if (options.transnb!=None):
# check for rotation.dat and translation.dat
checkFile("rotation.dat", "rotation file is required.")
checkFile("translation.dat", "translation file is required.\nFormer users may rename translat.dat into translation.dat.")
trans=Rigidbody("translation.dat")

transnb=options.transnb

if options.start1 is True:
transnb -= 1

co=trans.getCoords(transnb)
translations=[[transnb+1,co]]

if transnb!= len(trans)-1:
co=trans.getCoords(options.transnb-1)
translations=[[options.transnb,co]]
transnb=options.transnb-1
if transnb!=len(trans)-1:
printFiles=False #don't append ligand, receptor, etc. unless this is the last translation point of the simulation


if (options.rotnb!=None):
rotations = [rotations[options.rotnb-1]]

# core attract algorithm
for trans in translations:
transnb+=1
print "@@@@@@@ Translation nb %i @@@@@@@" %(transnb)
print "@@@@@@@ Translation nb %i @@@@@@@" %(transnb+firstr)
rotnb=0
for rot in rotations:
rotnb+=1
print "----- Rotation nb %i -----"%rotnb
minimcounter=0
ligand=AttractRigidbody(lig)
if options.regions:
ligand=Mcoprigid(lig)
receptor=Mcoprigid(rec)
else:
ligand=AttractRigidbody(lig)
receptor=AttractRigidbody(rec)

center=ligand.FindCenter()
ligand.Translate(Coord3D()-center) #set ligand center of mass to 0,0,0
ligand.AttractEulerRotate(surreal(rot[0]),surreal(rot[1]),surreal(rot[2]))
ligand.Translate(trans[1])


for minim in minimlist:
minimcounter+=1
cutoff=math.sqrt(minim['squarecutoff'])
Expand All @@ -377,41 +406,77 @@ def check_ffversion(reduced):

#performs single minimization on receptor and ligand, given maxiter=niter and restraint constant rstk
forcefield=ff_specs['ff_class'](ff_specs['ff_file'], surreal(cutoff) )
rec.setTranslation(False)
rec.setRotation(False)
if options.regions:
mcopff = McopForceField(forcefield, surreal(cutoff))
receptor.setTranslation(False)
receptor.setRotation(False)

forcefield.AddLigand(rec)
forcefield.AddLigand(ligand)
if options.regions:
mcopff.setLigand(ligand)
mcopff.setReceptor(receptor)
else:
forcefield.AddLigand(receptor)
forcefield.AddLigand(ligand)
rstk=minim['rstk'] #restraint force
#if rstk>0.0:
#forcefield.SetRestraint(rstk)
lbfgs_minimizer=ff_specs['minimizer_class'](forcefield)
lbfgs_minimizer.minimize(niter)

if options.regions:
lbfgs_minimizer=Lbfgs(mcopff)
lbfgs_minimizer.minimize(niter)
else :
lbfgs_minimizer=ff_specs['minimizer_class'](forcefield)
lbfgs_minimizer.minimize(niter)

X=lbfgs_minimizer.GetMinimizedVars() #optimized freedom variables after minimization


#TODO: test and use CenterToOrigin() !
output=AttractRigidbody(ligand)
if options.regions:
output=Mcoprigid(ligand)
else:
output=AttractRigidbody(ligand)

center=output.FindCenter()
output.Translate(Coord3D()-center)
output.AttractEulerRotate(surreal(X[0]), surreal(X[1]), surreal(X[2]))
output.Translate(Coord3D(surreal(X[3]),surreal(X[4]),surreal(X[5])))
output.Translate(center)

ligand=AttractRigidbody(output)
if (options.single):
if options.regions:
ligand=Mcoprigid(output)
else:
ligand=AttractRigidbody(output)
if (options.single or (options.transnb and options.rotnb)):
ntraj=lbfgs_minimizer.GetNumberIter()
for iteration in range(ntraj):
traj = lbfgs_minimizer.GetMinimizedVarsAtIter(iteration)
for t in traj:
for t in traj[0:6]:
ftraj.write("%f "%t)
ftraj.write("\n")
ftraj.write("~~~~~~~~~~~~~~\n")
if (options.regions):
savedWeights = mcopff.getSavedWeights()
for i, region in enumerate(savedWeights[0]):
weight_variation.write("Region %i\t"%(i+1))
for k, copy in enumerate(region):
weight_variation.write("Copy %i\t"%(k+1))
weight_variation.write("\n\n")
for iteration in range(ntraj):
for region in savedWeights[iteration]:
weight_variation.write("\t\t")
for copy in region:
weight_variation.write("%f\t"%copy)
weight_variation.write("\n")
weight_variation.write("~~~~~~~~~~~~~~\n")



#computes RMSD if reference structure available
if (options.reffile):
rms=Rmsd_alias(ref, output)
if(options.regions):
rms=Rmsd_alias(ref, output.getCore())
else:
rms=Rmsd_alias(ref, output)
else:
rms="XXXX"

Expand All @@ -420,9 +485,14 @@ def check_ffversion(reduced):
#with the new ligand position
forcefield=ff_specs['ff_class'](ff_specs['ff_file'], surreal(500))
print "%4s %6s %6s %13s %13s" %(" ","Trans", "Rot", "Ener", "RmsdCA_ref")
pl = AttractPairList(rec, ligand,surreal(500))
print "%-4s %6d %6d %13.7f %13s" %("==", transnb, rotnb, forcefield.nonbon8(rec,ligand,pl), str(rms))
output.PrintMatrix()
if options.regions:
print "%-4s %6d %6d %13.7f %13s" %("==", transnb + firstr, rotnb, mcopff.CalcEnergy(receptor,ligand,forcefield,500), str(rms))
output.getCore().PrintMatrix() #getCore because PrintMatrix works on AttractRigidy and not Mcoprigid
printWeights(receptor.getWeights(), mcopff.getMcopE())
else:
pl = AttractPairList(receptor, ligand,surreal(500))
print "%-4s %6d %6d %13.7f %13s" %("==", transnb + firstr, rotnb, forcefield.nonbon8(receptor,ligand,pl), str(rms))
output.PrintMatrix()


#output compressed ligand and receptor:
Expand All @@ -435,8 +505,10 @@ def check_ffversion(reduced):
print compress_file("attract.inp")

# close trajectory file for single minimization
if (options.single):
if (options.single or (options.transnb and options.rotnb)):
ftraj.close()
if (options.regions):
weight_variation.close()
print "Saved all minimization variables (translations/rotations) in %s" %(trjname)

# print end and elapsed time
Expand Down
Loading