def getQuote(path): """ Get a quote to display for the refresh page. Uses fortune to generate a quote. Parameters: path: The path to the fortune script (str) Returns: quote: The quote to display (str) """ fortune = os.popen(path) quote = fortune.read() quote = string.replace(quote, "\n", "<BR>") quote = string.replace(quote, "\t", " "*5) quote = "%s<P>" % quote return quote
def splitInput(filename): """ Split the parallel input file into multiple async file names Parameters filename: The path to the original parallel input file (string) """ nproc = 0 file = open(filename) text = "" while 1: line = file.readline() if line == "": break text += line line = string.strip(line) if line.startswith("pdime"): # Get # Procs words = string.split(line) nproc = int(words[1]) * int(words[2]) * int(words[3]) if nproc == 0: sys.stderr.write("%s is not a valid APBS parallel input file!\n" % filename) sys.stderr.write("The inputgen script was unable to asynchronize this file!\n") sys.exit(2) period = string.find(filename,".") for i in range(nproc): outname = filename[0:period] + "-PE%i.in" % i outtext = string.replace(text, "mg-para\n","mg-para\n async %i\n" % i) outfile = open(outname, "w") outfile.write(outtext) outfile.close()
def parseLines(self, lines): """ Parse the lines """ for line in lines: if string.find(line, "ATOM") == 0: subline = string.replace(line[30:], "-", " -") words = string.split(subline) if len(words) < 4: #sys.stderr.write("Can't parse following line:\n") #sys.stderr.write("%s\n" % line) #sys.exit(2) continue self.gotatom = self.gotatom + 1 self.q = self.q + float(words[3]) rad = float(words[4]) center = [] for word in words[0:3]: center.append(float(word)) for i in range(3): self.minlen[i] = min(center[i] - rad, self.minlen[i]) self.maxlen[i] = max(center[i] + rad, self.maxlen[i]) elif string.find(line, "HETATM") == 0: self.gothet = self.gothet + 1
def getCharmmParams(self, residue, name): """ Get the forcefield definitions from the Charmm database Parameters residue: The residue (residue) name: The atom name (string) Returns resname: The name of the Charmm residue atomname: The name of the Charmm atom """ resname = residue.get("name") atomname = name # Nucleic Acid Substitutions if residue.get("type") == 4: resname = resname[0] if resname == "A": resname = "ADE" elif resname == "C": resname = "CYT" elif resname == "G": resname = "GUA" elif resname == "T": resname = "THY" if atomname == "C7": atomname = "C5M" elif atomname == "H71": atomname = "H51" elif atomname == "H72": atomname = "H52" elif atomname == "H73": atomname = "H53" elif resname == "U": resname = "URA" if atomname == "H5'1": atomname = "H5'" elif atomname == "H5'2": atomname = "H5''" elif atomname == "H2'1": atomname = "H2'" elif atomname in ["H2'2", "HO'2"]: atomname = "H2''" if residue.getAtom("O2'") == None: if atomname in ["C2'", "H2'", "H2''"]: resname = "DEO1" if residue.getAtom("H5T") != None: if atomname in ["H5T", "O5'", "C5'"]: resname = "5TER" if residue.getAtom("H3T") != None: if atomname in ["H3T", "O3'", "C3'"]: resname = "3TER" # Terminal/Water Substitutions if residue.get("isNterm"): if resname == "GLY" and atomname in [ "N", "H", "H2", "H3", "CA", "HA2", "HA3" ]: resname = "GLYP" if atomname == "H": atomname = "HT1" elif atomname == "H2": atomname = "HT2" elif atomname == "H3": atomname = "HT3" elif resname == "PRO" and atomname in [ "N", "HN1", "HN2", "CD", "CA", "HD1", "HD2", "HA", "H2", "H3" ]: resname = "PROP" if atomname == "H2": atomname = "HN1" elif atomname == "H3": atomname = "HN2" elif resname == "ACE": if atomname == "CH3": atomname = "CAY" elif atomname == "HH31": atomname = "HY1" elif atomname == "HH32": atomname = "HY2" elif atomname == "HH33": atomname = "HY3" elif atomname == "C": atomname = "CY" elif atomname == "O": atomname = "OY" else: if atomname in ["N", "H", "H2", "H3", "CA", "HA"]: resname = "NTER" if atomname == "H": atomname = "HT1" elif atomname == "H2": atomname = "HT2" elif atomname == "H3": atomname = "HT3" elif residue.get("isCterm"): if atomname in ["O", "OXT", "C"]: resname = "CTER" if atomname == "O": atomname = "OT1" elif atomname == "OXT": atomname = "OT2" elif residue.get("type") == 3: resname = "TP3M" if atomname == "O": atomname = "OH2" # Residue substitutions if resname == "ILE": if atomname == "CD1": atomname = "CD" elif atomname == "HD11": atomname = "HD1" elif atomname == "HD12": atomname = "HD2" elif atomname == "HD13": atomname = "HD3" elif atomname == "HG12": atomname = "HG11" elif atomname == "HG13": atomname = "HG12" elif resname == "CYS" and "HG" not in residue.get("map"): if atomname == "CB": resname = "DISU" atomname = "1CB" elif atomname == "SG": resname = "DISU" atomname = "1SG" elif resname == "HIS": if "HD1" in residue.get("map") and "HE2" in residue.get("map"): resname = "HSP" elif "HD1" in residue.get("map"): resname = "HSD" elif "HE2" in residue.get("map"): resname = "HSE" elif resname == "GLU" or resname == "GLH": if "HE1" in residue.get("map"): if atomname == "HE1": atomname = "HE2" elif atomname == "OE1": atomname = "OE2" elif atomname == "OE2": atomname = "OE1" if atomname in [ "CG", "HG3", "HG1", "HG2", "CD", "OE1", "OE2", "HE2" ]: resname = "GLUP" else: resname == "GLU" elif "HE2" in residue.get("map"): if atomname in [ "CG", "HG3", "HG1", "HG2", "CD", "OE1", "OE2", "HE2" ]: resname = "GLUP" else: resname == "GLU" elif resname == "ASP" or resname == "ASH": if "HD1" in residue.get("map"): if atomname == "HD1": atomname = "HD2" elif atomname == "OD1": atomname = "OD2" elif atomname == "OD2": atomname = "OD1" if atomname in [ "CB", "HB3", "HB1", "HB2", "CG", "OD1", "OD2", "HD2" ]: resname = "ASPP" else: resname == "ASP" elif "HD2" in residue.get("map"): if atomname in [ "CB", "HB3", "HB1", "HB2", "CG", "OD1", "OD2", "HD2" ]: resname = "ASPP" else: resname == "ASP" # HETATM Substitutions if resname == "ACE": if atomname == "CH3": atomname = "CAY" elif atomname == "HH31": atomname = "HY1" elif atomname == "HH32": atomname = "HY2" elif atomname == "HH33": atomname = "HY3" elif atomname == "C": atomname = "CY" elif atomname == "O": atomname = "OY" elif resname == "ADP": atomname = string.replace(atomname, "*", "\'") # Hydrogen Substitutions if atomname == "H": atomname = "HN" elif atomname == "HA2": atomname = "HA1" elif atomname == "HA3": atomname = "HA2" elif atomname == "HB2" and resname not in ["ALA"]: atomname = "HB1" elif atomname == "HB3" and resname not in ["ALA"]: atomname = "HB2" elif atomname == "HD2" and resname not in [ "HSP", "HSE", "HSD", "ASPP" ]: atomname = "HD1" elif atomname == "HD3" and resname not in ["HIS", "HSE", "HSD"]: atomname = "HD2" elif atomname == "HE2" and resname not in [ "TRP", "HSP", "HSE", "HSD", "GLUP" ]: atomname = "HE1" elif atomname == "HE3" and resname not in ["TRP", "HSP", "HSE", "HSD"]: atomname = "HE2" elif atomname == "HG2": atomname = "HG1" elif atomname == "HG3": atomname = "HG2" elif atomname == "HG" and resname in ["SER", "CYS"]: atomname = "HG1" return resname, atomname
def createResults(header, input, name, time, missedligands=[]): """ Create the results web page for CGI-based runs Parameters header: The header of the PQR file (string) input: A flag whether an input file has been created (int) tmpdir: The resulting file directory (string) name: The result file root name, based on local time (string) time: The time taken to run the script (float) missedligands: A list of ligand names whose parameters could not be assigned. Optional. (list) """ newheader = string.replace(header, "\n", "<BR>") newheader = string.replace(newheader," "," ") filename = "%s%s%s.html" % (LOCALPATH, TMPDIR, name) file = open(filename, "w") file.write("<html>\n") file.write("<head>\n") file.write("<title>PDB2PQR Results</title>\n") file.write("<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">\n" % STYLESHEET) file.write("</head>\n") file.write("<body>\n") file.write("<h2>PDB2PQR Results</h2>\n") file.write("<P>\n") file.write("Here are the results from PDB2PQR. The files will be available on the ") file.write("server for a short period of time if you need to re-access the results.<P>\n") file.write("<a href=\"%s%s%s.pqr\">%s.pqr</a><BR>\n" % (WEBSITE, TMPDIR, name, name)) if input: file.write("<a href=\"%s%s%s.in\">%s.in</a><BR>\n" % (WEBSITE, TMPDIR, name, name)) pkaname = "%s%s%s.propka" % (LOCALPATH, TMPDIR, name) if os.path.isfile(pkaname): file.write("<a href=\"%s%s%s.propka\">%s.propka</a><BR>\n" % (WEBSITE, TMPDIR, name, name)) typename = "%s%s%s-typemap.html" % (LOCALPATH, TMPDIR, name) if os.path.isfile(typename): file.write("<a href=\"%s%s%s-typemap.html\">%s-typemap.html</a><BR>\n" % (WEBSITE, TMPDIR, name, name)) file.write("<P>The header for your PQR file, including any warnings generated, is:<P>\n") file.write("<blockquote><code>\n") file.write("%s<P>\n" % newheader) file.write("</code></blockquote>\n") if missedligands != []: file.write("The forcefield that you have selected does not have ") file.write("parameters for the following ligands in your PDB file. Please visit ") file.write("<a href=\"http://davapc1.bioch.dundee.ac.uk/programs/prodrg/\">PRODRG</a> ") file.write("to convert these ligands into MOL2 format. This ligand can the be ") file.write("parameterized in your PDB2PQR calculation using the PEOE_PB methodology via ") file.write("the 'Assign charges to the ligand specified in a MOL2 file' checkbox:<P>\n") file.write("<blockquote><code>\n") for item in missedligands: file.write("%s<BR>\n" % item) file.write("<P></code></blockquote>\n") file.write("If you would like to run PDB2PQR again, please click <a href=\"%s%s\">\n" % (WEBSITE, WEBNAME)) file.write("here</a>.<P>\n") file.write("<P>Thank you for using the PDB2PQR server!<P>\n") file.write("<font size=\"-1\"><P>Total time on server: %.2f seconds</font><P>\n" % time) file.write("<font size=\"-1\"><CENTER><I>Last Updated %s</I></CENTER></font>\n" % __date__) file.write("</body>\n") file.write("</html>\n")
def read4(self, filename): """Read from and set the current state according to the AutoGrid4 file. """ self.gpf_filename = filename gpf_ptr = open(filename) lines = gpf_ptr.readlines() gpf_ptr.close() keys = list(self.keys()) self.file_params = [] for line in lines: #print "reading ", line words = string.split(string.replace(line, '\t', ' ')) #print "words=", words if words != [] and words[0][0] != '#': p = words[0] if p not in keys: print("WARNING: unrecognized parameter in ", filename, ":\n", p) continue #print "p=", p # maintain a list of the parameters read from the file if self.file_params == [] or p != self.file_params[-1]: self.file_params.append(p) # parse the line l = len(words) for i in range(l): if words[i][0] == '#': l = i break values = words[1:l] if p == 'parameter_file': self['custom_parameter_file']['value'] = 1 self['parameter_file']['value'] = values[0] elif ((len(values) == 1) and (type(self[p]['default']) != list)): self[p]['value'] = self._get_val(values[0]) #print " value=", self[p]['value'] #if words[0]=='types': # #in this case have to set flags for possible new type # extraLigandTypes = self.checkLigTypes(values[0]) #setting dielectric from a gpf is no longer supported #instead must be set in a parameter library file #elif p=='dielectric': # self['dielectric4']['value'] = self._get_val(values[0]) elif p == 'ligand_types': self['ligand_types']['value'] = string.join(words[1:l]) elif p == 'receptor_types': self['receptor_types']['value'] = string.join(words[1:l]) elif words[0] == 'covalentmap': #in this case set: #covalent_ coords,constant,energy_barrier,half_width self['covalentmap']['value'] = 1 self['covalent_half_width']['value'] = float(values[1]) self['covalent_energy_barrier']['value'] = float(values[2]) self['covalent_coords']['value'] = [float(values[3]),\ float(values[4]), float(values[5])] self[p]['value'] = [] elif words[0] == 'gridcenter' and l > 1: #need to convert to float newvalue = [ float(values[0]), float(values[1]), float(values[2]) ] self['gridcenterAuto']['value'] = 0 self[p]['value'] = newvalue else: #print "in else for ", p self[p]['value'] = [] for v in values: self[p]['value'].append(self._get_val(v))
def read(self, filename): """Read from and set the current state according to the file. """ self.gpf_filename = filename gpf_ptr = open(filename) lines = gpf_ptr.readlines() gpf_ptr.close() self.file_params = [] checkedTypes = [] extraLigandTypes = [] keys = list(self.keys()) for line in lines: words = string.split(string.replace(line, '\t', ' ')) if words != [] and words[0][0] != '#': p = words[0] if p not in keys: print("WARNING: unrecognized parameter in ", filename, ":\n", p) continue # maintain a list of the parameters read from the file if self.file_params == [] or p != self.file_params[-1]: self.file_params.append(p) # parse the line l = len(words) for i in range(l): if words[i][0] == '#': l = i break values = words[1:l] if ((len(values) == 1) and (type(self[p]['default']) != list)): self[p]['value'] = self._get_val(values[0]) if words[0] == 'types': #in this case have to set flags for possible new type extraLigandTypes = self.checkLigTypes(values[0]) elif words[0] == 'ligand_types': self[p]['value'] = string.join(words[1:l]) elif words[0] == 'receptor_types': self[p]['value'] = string.join(words[1:l]) elif words[0] == 'covalentmap': #in this case set: #covalent_ coords,constant,energy_barrier,half_width self['covalentmap']['value'] = 1 self['covalent_half_width']['value'] = float(values[0]) self['covalent_energy_barrier']['value'] = float(values[1]) self['covalent_coords']['value'] = [float(values[2]),\ float(values[3]), float(values[4])] self[p]['value'] = [] elif words[0] == 'nbp_r_eps': #in this case have to check for nhb,ohb,shb +mset #in this case have to check for new type constants ptype = words[-1] if len(words[l]) == 1: keyWord = words[l + 1] else: keyWord = words[l][1:] mtype = string.split(keyWord, '-')[0] ntype = string.split(keyWord, '-')[1] if mtype in checkedTypes: continue if mtype in ['N', 'O', 'S'] and ntype == 'H': #check for 12 6 vs 12 10 here ind = mtype + 'HB' if values[3] == '10': self[ind]['value'] = 1 else: self[ind]['value'] = 0 checkedTypes.append(mtype) if mtype in extraLigandTypes: i = ptype + mtype + ntype Rij[i] = float(words[1]) epsij[i] = float(words[2]) elif words[0] == 'sol_par': if len(words[l]) == 1: mtype = words[l + 1] else: mtype = words[l][1] if mtype in extraLigandTypes: SolVol[mtype] = float(values[0]) SolPar[mtype] = float(values[1]) elif words[0] == 'constant': if len(words[l]) == 1: mtype = words[l + 1] else: mtype = words[l][1] SolCon[mtype] = float(values[0]) elif words[0] == 'gridcenter' and l > 1: #need to convert to float newvalue = [ float(values[0]), float(values[1]), float(values[2]) ] self['gridcenterAuto']['value'] = 0 self[p]['value'] = newvalue else: self[p]['value'] = [] for v in values: self[p]['value'].append(self._get_val(v))