1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
|
#!/usr/bin/env python
# Combine OA and HD maps for providing the W map
# for water molecules affinity
# The first map should be OA, the second HD
import getopt
from sys import argv, exit
import os
#from numpy import array
# VARIABLES
# weight of the affinity (to scale the interaction)
default_weight = .6
mode = "BEST"
ENTROPY=-0.2
#O_weight = .33
#hd_boost = 1.7
O_weight = 1.
hd_boost = 1.
#mode = "AVG"
#mode = "COOP"
#mode = "BOOST"
#if mode == "BOOST":
# default_weight /= .05
#mode = "BEST"
#mode = "BOOST"
#mode = "BEST_W"
#ENTROPY=0.0 #TODO <============= TEST THIS ON 2CCS to check if the penalty will lead to submerge the ligand inside the binding site
#ENTROPY=0.5
O=0
H=0
#--OXYGEN
#O_weight = .33
#O_weight = .5
#O_weight = 1
#--HYDROGEN
#hd_boost = 1.8
#hd_boost = 1.7
#hd_boost = 1.0
#hd_boost = 0.6
def getLines(file, mode = "r"):
fp = open(file, 'r')
l = fp.readlines()
fp.close()
return l
def usage():
#print "\n WET\n\n"
myname = os.path.basename(argv[0])
print("""\n
/\/\ __ _ _ __
/ \ / _` | '_ \
/ /\/\ \ (_| | |_) | .-.
\/ \/\__,_| .__/ ( )_
|_| _/-'(_)
__ __ _ (_)
/ / /\ \ \__ _| |_ ___ _ __
\ \/ \/ / _` | __/ _ \ '__|
\ /\ / (_| | || __/ |
\/ \/ \__,_|\__\___|_|
""")
print("\tUSAGE\n\t\t%s -r | -o -h [options] \n\n" % myname)
print("\tINPUT\n\t\tEither the receptor filename or the map files.\n")
print("\t\t\t-r protein.pdbqt : the receptor filename is used to guess the OA and HD filenames")
print("\n\t\t\t\t *OR*\n")
print("\t\t\t-o protein.OA.map : OA map filename (omit if -r is used)")
print("\t\t\t-h protein.HD.map : HD map filename (omit if -r is used)")
print("\tOUTPUT\n\t\tW map.\n")
#print "\t\tBy default the program saves the output by adding the suffix \"_HYDRO\" to the input PDBQT.\n"
#print "\tOPTIONS"
#print "\t\t-o\tIf \"output_filename\" is speficied, the output will be saved with this filename.\n\t\t\tFull path names can be used."
#print "\t\t\tIf \"output_directory\" is provided, the output will be saved in the specified path by\n\t\t\tusing the default filename.\n\n"
#print "\t\t-g\thydrate only the input atoms comprised in the volume specified by the GPF.\n\n"
#print "\t\t-F\tThe output will be saved as \"input_HYDRO.pdbqt\" even if no waters are added."
#print "\t\t\t(the default is to not to write the output if no waters have been added)"
#print "\n\n"
print("\tOPTIONS\n")
print("\t\t-m (best,avg,coop..): mix method (default 'best')")
print("\t\t-e float : entropy penalty value (default: 0.0)")
print("\t\t-O float : oxygen map weight (default: 1.0)")
print("\t\t-H float : hydrogen map weight (default: 1.0)")
print("\t\t-s protein.W.map : W map output filename (default: protein.W.map.[mix method].w[eight].o[xygen weight].h[ydrogen weight].E[ntropy correction])")
print("\n\n")
print("\n\tReference ")
print("\t----------")
print("\t Please cite: Stefano Forli and Arthur J. Olson, J. Med. Chem., 2012, 55 (2), pp 623-638")
print("\t DOI: 10.1021/jm2005145")
print("\n\n")
try:
options, pdbqt = getopt.getopt(argv[1:], 'o:h:m:e:O:H:s:w:r:')
# -r protein.pdbqt
# -o protein.OA.map
# -h protein.HD.map
# -s protein.W.map
# -w 0.5
# -m best,avg,coop...
# -e entropy
# -O oxygen_weight
# -H hydrogen_weight
except getopt.GetoptError as err:
usage()
print(str(err), "\n")
exit(2)
opts = {}
for o, a in options: # populate the options
opts[o] = a
try:
opts
except:
usage()
exit(1)
print("ADD PWD AND FILE SUMMARY")
if '-r' in opts:
protein = os.path.basename(opts['-r'])
name = protein.rsplit(".")[0]
print(" receptor : ", protein)
firstMap = name+".OA.map"
secondMap = name+".HD.map"
print(" OA map ->", firstMap)
print(" HD map ->", secondMap)
else:
if not "-o" in opts or not "-h" in opts:
print("missing input1,2 or output")
usage()
exit(1)
firstMap = opts['-o']
secondMap = opts['-h']
if '-w' in opts:
try:
weight = float(opts['-w'])
except:
print("wrong weight")
exit(1)
else:
weight = default_weight
print(" => Water map weight : DEFAULT [ %1.2f ]" % weight)
if '-m' in opts:
if opts['-m'] == "best":
mode = "BEST"
if opts['-m'] == "best_new":
mode = "BEST_NEW"
if opts['-m'] == "optimal":
mode = "OPTIMAL"
if opts['-m'] == "optimal_spherical":
mode = "OPTIMAL_SPHERICAL"
if opts['-m'] == "avg":
mode = "AVG"
if opts['-m'] == "coop":
mode = "COOP"
if opts['-m'] == "boost":
mode = "BOOST"
if opts['-m'] == "best_w":
mode = "BEST_W"
#else:
# mode = "BEST"
if mode == "BOOST":
default_weight /= .05
if "-e" in opts:
ENTROPY = float(opts['-e'])
if '-O' in opts:
O_weight = float(opts['-O'])
if '-H' in opts:
hd_boost = float(opts['-H'])
if '-s' in opts:
outputFile = opts['-s']
else:
# OLD for compatibility sake
# outputFile = "protein.W.map.%s.w%1.2f.O%1.1f.H%1.1f.E%1.1f" % (mode, weight, O_weight, hd_boost, ENTROPY )
outputFile = "protein.W.%s.w%1.2f.O%1.2f.H%1.2f.E%1.2f.map" % (mode, weight, O_weight, hd_boost, ENTROPY )
# protein.W.map.BEST.w0.5.O0.3.H1.3.E0
print("\n MapWater generator\n =====================")
print(" mode : ", mode)
print(" weight : ", weight)
print(" HD_weight : ", hd_boost)
print(" OA_weight : ", O_weight)
print(" entropy : ", ENTROPY)
##################
# mixing modes
def best(first, second, positive = False ): #, hd_boost = hd_boost):
global O, H
"""
- Return the best value between two map values
- If any positive values are found, 0 is returned by default
- by default it should be first=OA, second=HD
"""
first *= O_weight
second *= hd_boost
# TODO TODO TODO TODO
# TODO POTENTIAL ERROR???
# TODO - positive values for oxygen are misleading
# TODO TODO TODO TODO
if not positive and (first > 0 or second > 0): #
# TODO add a smoothing function for positive values?
return ENTROPY
else:
if first < second :
O += 1
return first * weight
else:
H += 1
#print "First: %2.6f\tSecond: %2.6f" % (first, second)
return second * weight
def BEST(oxygen, hydrogen):
global O, H
"""
- Return the best value between two map values
- If any positive values are found, 0 is returned by default
- by default it should be first=OA, second=HD
"""
oxygen *= O_weight
hydrogen *= hd_boost
# TODO TODO TODO TODO
# TODO POTENTIAL ERROR!!!
# TODO - positive values for oxygen are misleading
# ATTEMPT TO FIX...
# TODO TODO TODO TODO
if hydrogen > 0: # HD is the smaller probe: if it doesn't fit, neither does OA
return ENTROPY
else:
if oxygen < hydrogen :
O += 1
return oxygen * weight
else:
H += 1
return hydrogen * weight
def optimal(oxygen, hydrogen):
global O, H
# NEVER TESTED
oxygen *= O_weight
hydrogen *= hd_boost
#if (hydrogen < 0 and hydrogen > -0.2) and ():
# return 0
if hydrogen >= 0: # HD is the smaller probe: if it doesn't fit, neither does OA
return ENTROPY
else:
if oxygen < 0 and hydrogen < 0 : # both values are negative: COMBINE
O += 1
H += 1
return (oxygen + hydrogen) * weight
# ..... or take the best
elif oxygen < hydrogen:
O += 1
return oxygen * weight
elif hydrogen < oxygen:
H += 1
return hydrogen * weight
def optimal_spherical(oxygen, hydrogen):
global O, H
# NEVER TESTED
oxygen *= O_weight
hydrogen *= hd_boost
oh_balance = 1
#if (hydrogen < 0 and hydrogen > -0.2) and ():
# return 0
if hydrogen >= 0: # HD is the smaller probe: if it doesn't fit, neither does OA
return ENTROPY
else:
if oxygen < 0 and hydrogen < 0 : # both values are negative: COMBINE
O += 1
H += 1
#print "sphere!"
return ((oxygen + hydrogen)*oh_balance) * weight
# ..... or take the best
elif oxygen < hydrogen:
O += 1
return oxygen * weight
elif hydrogen < oxygen:
H += 1
return hydrogen * weight
def cooperate(first, second, positive = False):
global O, H
"""
- Return the sum of value between two map values
- If any positive values are found, 0 is returned by default
"""
first *= O_weight
second *= hd_boost
if not positive and (first > 0 or second > 0):
# TODO add a smoothing function for positive values?
return ENTROPY
else:
value = (first + second) * weight
O += 1
H += 1
# check
if first > 0 or second >0:
print("################ERROR!!!! ###################")
#
return value
def coop_blend():
global O, H
"""
- Return the sum of value between two map values
- If any positive values are found, 0 is returned by default
"""
first *= O_weight
second *= hd_boost
if not positive and (first > 0 or second > 0):
# TODO add a smoothing function for positive values?
return ENTROPY
else:
# TODO
# average of the total two contributions?
value = ((first + second)/2) * weight
O += 1
H += 1
# check
if first > 0 or second >0:
print("################ERROR!!!! ###################")
#
def best_weighted(first, second, positive = False):
global O, H
# TODO test different parameters to check if there's
# a real advantage
"""
- Return the best value between two map values
- If any positive values are found, 0 is returned by default
- WEIGHTED: the OA map is scaled by weight to account for the higher
intensity of OA maps versus HD
"""
first *= O_weight
second *= hd_boost
if not positive and (first > 0 or second > 0):
return 0 + ENTROPY
else:
if first < second :
O += 1
return first*weight
else:
H += 1
return second*weight
def avg(first, second, positive = False):
"""
- Return the average value between two map values
- If any positive values are found, 0 is returned by default
"""
if not positive and (first > 0 or second > 0):
return ENTROPY
else:
value = ( (first + second)/2 ) * weight
return value
def boost(first, second, positive = False):
if not positive and (first > 0 or second > 0):
return ENTROPY
else:
value = ((first*7+second*7)/2) * weight
return value
#try:
# weight = float(argv[4])
# print " => Water map weight :", weight
#except:
# weight = default_weight
# print " => Water map weight : DEFAULT [ %1.2f ]" % weight
#weight = 1
#weight = 4
#if not hd_boost == 1:
# print " => HD boost ", hd_boost, "!"
#if not ENTROPY == 0:
# print " => Entropy factor :", ENTROPY
#else:
# print "[ Entropy is ignored ]"
#print " => Calculated value :", mode
#print "\n\n"
#firstMap = argv [1]
#secondMap = argv [2]
#outputFile = argv [3]
data=[]
data2=[]
total=[]
HEADER=[]
try:
#MAP1 = open( firstMap, 'r' )
MAP1 = getLines(firstMap)
except:
print("ERROR: the map %s can't be open" % firstMap)
exit(1)
try:
#MAP2 = open( secondMap, 'r' )
MAP2 = getLines(secondMap)
except:
print("ERROR: the map %s can't be open" % secondMap)
exit(1)
try:
DIFFERENCE = open ( outputFile, 'w' )
except:
print("ERROR: impossible to open the output map", outputFile)
exit(1)
HEADER = MAP1[0:6]
data = list(map(float, MAP1[6:]))
data2 = list(map(float, MAP2[6:]))
"""
for skip in "123456":
HEADER.append(MAP1.next())
for line in MAP1:
data.append(float(line))
for skip in "123456":
MAP2.next()
for line in MAP2:
data2.append(float(line))
"""
"""
MAP1 = open( firstMap, 'r' ).readlines()
MAP2 = open( secondMap, 'r' ).readlines()
DIFFERENCE = open ( outputFile, 'w' )
HEADER = MAP1[0:6]
data = array(MAP1[6:], float)
data2 = array(MAP2[6:], float)
"""
highest = 9999
lowest = -9999
if mode == "BEST":
function = best
elif mode == "AVG":
funcion = avg
elif mode == "COOP":
function = cooperate
elif mode == "BOOST":
function = boost
elif mode == "BEST_W":
function = best_weighted
elif mode == "BEST_NEW":
function = BEST
elif mode == "OPTIMAL":
function = optimal
elif mode == "OPTIMAL_SPHERICAL":
function = optimal_spherical
for i in range(len(data)):
first=data[i]
second=data2[i]
value = function(first, second)
if value > lowest:
lowest = value
if value < highest:
highest = value
total.append(value)
"""
if mode == "BEST":
value = best(first, second)
elif mode == "AVG":
value = avg(first, second)
elif mode == "COOP":
value = cooperate(first, second)
elif mode == "BOOST":
value = boost(first, second)
elif mode == "BEST_W":
value = best_weighted(first, second)
elif mode == "BEST_NEW":
value = BEST(first, second)
elif mode == "OPTIMAL":
value = optimal(first, second)
elif mode == "OPTIMAL_SPHERICAL":
value = optimal_spherical(first, second)
"""
#total = map(function, data, data2)
# output the results
for index in range(len(HEADER)):
DIFFERENCE.write(str(HEADER[index]))
for index in range(len(total)):
try:
value = "%1.4f" % (total[index])
except:
print("problem")
DIFFERENCE.write(value+'\n')
DIFFERENCE.close
O = float(O)
H = float(H)
tot = H+O
o_pc = (O/tot)*100
h_pc = (H/tot)*100
print("\n Output info ")
print(" --------------------")
print(" filename :", outputFile)
print(" OA points : %3.2f%s" % ( o_pc , "%"))
print(" HD points : %3.2f%s\n" % ( h_pc, "%"))
#print O, H
print(" lowest map value : %3.2f" % highest)
print(" highest map value : %3.2f" % lowest)
print("\n")
|