File size: 3,808 Bytes
10f2621 | 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 | import os
import numpy
from subprocess import Popen, PIPE
import pymesh
import tempfile
from default_config.global_vars import apbs_bin, pdb2pqr_bin, multivalue_bin
import random
"""
Modified from:
computeAPBS.py: Wrapper function to compute the Poisson Boltzmann electrostatics for a surface using APBS.
Pablo Gainza - LPDI STI EPFL 2019
"""
def computeAPBS(vertices, pdb_file, tmp_file_base,clear=False):
"""
Calls APBS, pdb2pqr, and multivalue and returns the charges per vertex
"""
if not clear:
pdb2pqr = pdb2pqr_bin + " --ff=parse --whitespace --noopt --apbs-input %s %s"# + tempfile.mktemp()
# pdb2pqr = pdb2pqr_bin + " --clean --whitespace --noopt --apbs-input %s %s"# + tempfile.mktemp() # 上一行由于确实太多办法计算表面的时候再用这个
else:
pdb2pqr = pdb2pqr_bin + " --clean --whitespace --noopt --apbs-input %s %s"# + tempfile.mktemp() # 上一行由于确实太多办法计算表面的时候再用这个
make_pqr = pdb2pqr % (pdb_file, tmp_file_base)
os.system(make_pqr)
print('os.system(make_pqr)',os.system(make_pqr))
apbs = apbs_bin + " %s"
make_apbs = apbs % (tmp_file_base+".in")
# os.system(make_apbs)
print(make_apbs)
print('os.system(make_apbs)',os.system(make_apbs))
vertfile = open(tmp_file_base + ".csv", "w")
for vert in vertices:
vertfile.write("{},{},{}\n".format(vert[0], vert[1], vert[2]))
vertfile.close()
multivalue = multivalue_bin + " %s %s %s"
make_multivalue = multivalue % (tmp_file_base+".csv", tmp_file_base+".dx", tmp_file_base+"_out.csv")
# print(make_multivalue)
try:
os.system(make_multivalue)
except Exception as e:
print(e)
# Read the charge file
chargefile = open(tmp_file_base + "_out.csv")
charges = numpy.array([0.0] * len(vertices))
for ix, line in enumerate(chargefile.readlines()):
charges[ix] = float(line.split(",")[3])
# os.system("rm " + tmp_file_base + "*")
# os.system("rm io.mc")
return charges
""" ORIGINAL FUNCTION
'''
computeAPBS.py: Wrapper function to compute the Poisson Boltzmann electrostatics for a surface using APBS.
Pablo Gainza - LPDI STI EPFL 2019
This file is part of MaSIF.
Released under an Apache License 2.0
'''
def computeAPBS(vertices, pdb_file, tmp_file_base = tempfile.mktemp()):
#Calls APBS, pdb2pqr, and multivalue and returns the charges per vertex
#fields = tmp_file_base.split("/")[0:-1]
#directory = "/".join(fields) + "/"
fields = tmp_file_base
directory = str(fields) + "/"
filename_base = tmp_file_base.split("/")[-1]
pdbname = pdb_file.split("/")[-1]
args = [
pdb2pqr_bin,
"--ff=parse",
"--whitespace",
"--noopt",
"--apbs-input",
pdbname,
filename_base,
]
p2 = Popen(args, stdout=PIPE, stderr=PIPE, cwd=directory)
stdout, stderr = p2.communicate()
args = [apbs_bin, filename_base + ".in"]
p2 = Popen(args, stdout=PIPE, stderr=PIPE, cwd=directory)
stdout, stderr = p2.communicate()
vertfile = open(directory + "/" + filename_base + ".csv", "w")
for vert in vertices:
vertfile.write("{},{},{}\n".format(vert[0], vert[1], vert[2]))
vertfile.close()
args = [
multivalue_bin,
filename_base + ".csv",
filename_base + ".dx",
filename_base + "_out.csv",
]
p2 = Popen(args, stdout=PIPE, stderr=PIPE, cwd=directory)
stdout, stderr = p2.communicate()
# Read the charge file
chargefile = open(tmp_file_base + "_out.csv")
charges = numpy.array([0.0] * len(vertices))
for ix, line in enumerate(chargefile.readlines()):
charges[ix] = float(line.split(",")[3])
return charges
""" |