def __init__(self, form): '''Gleans all information about the user selected options and uploaded files. Also validates the user input. Raises WebOptionsError if there is any problems.''' #options to pass to runPDB2PQR self.runoptions = {} #Additional options to pass to google analytics along with the run options. #These are included in has_key(), __contains__(), and __getitem__() calls. self.otheroptions = {} self.runoptions['debump'] = "DEBUMP" in form self.runoptions['opt'] = "OPT" in form if 'FF' in form: self.ff = form["FF"].value.lower() else: raise WebOptionsError('Force field type missing from form.') if "PDBID" in form and form["PDBID"].value and form["PDBSOURCE"].value == 'ID': self.pdbfile = utilities.getPDBFile(form["PDBID"].value) if self.pdbfile is None: raise WebOptionsError('The pdb ID provided is invalid.') self.pdbfilestring = self.pdbfile.read() self.pdbfile = StringIO(self.pdbfilestring) self.pdbfilename = form["PDBID"].value elif "PDB" in form and form["PDB"].filename and form["PDBSOURCE"].value == 'UPLOAD': self.pdbfilestring = form["PDB"].value self.pdbfile = StringIO(self.pdbfilestring) self.pdbfilename = sanitizeFileName(form["PDB"].filename) else: raise WebOptionsError('You need to specify a pdb ID or upload a pdb file.') if "PKACALCMETHOD" in form: if form["PKACALCMETHOD"].value != 'none': if 'PH' not in form: raise WebOptionsError('Please provide a pH value.') phHelp = 'Please choose a pH between 0.0 and 14.0.' try: ph = float(form["PH"].value) except ValueError: raise WebOptionsError('The pH value provided must be a number! ' + phHelp) if ph < 0.0 or ph > 14.0: text = "The entered pH of %.2f is invalid! " % ph text += phHelp raise WebOptionsError(text) self.runoptions['ph'] = ph #build propka and pdb2pka options if form['PKACALCMETHOD'].value == 'propka': self.runoptions['ph_calc_method'] = 'propka' self.runoptions['ph_calc_options'] = utilities.createPropkaOptions(ph, False) if form['PKACALCMETHOD'].value == 'pdb2pka': self.runoptions['ph_calc_method'] = 'pdb2pka' self.runoptions['ph_calc_options'] = {'output_dir': 'pdb2pka_output', 'clean_output': True, 'pdie': 8, 'sdie': 80, 'pairene': 1.0} self.otheroptions['apbs'] = "INPUT" in form self.otheroptions['whitespace'] = "WHITESPACE" in form if self.ff == 'user': if "USERFF" in form and form["USERFF"].filename: self.userfffilename = sanitizeFileName(form["USERFF"].filename) self.userffstring = form["USERFF"].value self.runoptions['userff'] = StringIO(form["USERFF"].value) else: text = "A force field file must be provided if using a user created force field." raise WebOptionsError(text) if "USERNAMES" in form and form["USERNAMES"].filename: self.usernamesfilename = sanitizeFileName(form["USERNAMES"].filename) self.usernamesstring = form["USERNAMES"].value self.runoptions['usernames'] = StringIO(form["USERNAMES"].value) else: text = "A names file must be provided if using a user created force field." raise WebOptionsError(text) if "FFOUT" in form and form["FFOUT"].value != "internal": self.runoptions['ffout'] = form["FFOUT"].value self.runoptions['chain'] = "CHAIN" in form self.runoptions['typemap'] = "TYPEMAP" in form self.runoptions['neutraln'] = "NEUTRALN" in form self.runoptions['neutralc'] = "NEUTRALC" in form self.runoptions['drop_water'] = "DROPWATER" in form if (self.runoptions['neutraln'] or self.runoptions['neutraln']) and \ self.ff != 'parse': raise WebOptionsError('Neutral N-terminus and C-terminus require the PARSE forcefield.') if "LIGAND" in form and form['LIGAND'].filename: self.ligandfilename=sanitizeFileName(form["LIGAND"].filename) ligandfilestring = form["LIGAND"].value # for Windows and Mac style newline compatibility for pdb2pka ligandfilestring = ligandfilestring.replace('\r\n', '\n') self.ligandfilestring = ligandfilestring.replace('\r', '\n') self.runoptions['ligand'] = StringIO(self.ligandfilestring) if self.pdbfilename[-4:]==".pdb": self.pqrfilename = "%s.pqr" % self.pdbfilename[:-4] else: self.pqrfilename = "%s.pqr" % self.pdbfilename #Always turn on summary and verbose. self.runoptions['verbose'] = True self.runoptions['selectedExtensions'] = ['summary']
def __init__(self, form): '''Gleans all information about the user selected options and uploaded files. Also validates the user input. Raises WebOptionsError if there is any problems.''' #options to pass to runPDB2PQR self.runoptions = {} #Additional options to pass to google analytics along with the run options. #These are included in has_key(), __contains__(), and __getitem__() calls. self.otheroptions = {} self.runoptions['debump'] = form.has_key("DEBUMP") self.runoptions['opt'] = form.has_key("OPT") if form.has_key('FF'): self.ff = form["FF"].value.lower() else: raise WebOptionsError('Force field type missing from form.') if form.has_key("PDBID") and form["PDBID"].value and form[ "PDBSOURCE"].value == 'ID': self.pdbfile = utilities.getPDBFile(form["PDBID"].value) if self.pdbfile is None: raise WebOptionsError('The pdb ID provided is invalid.') self.pdbfilestring = self.pdbfile.read() self.pdbfile = StringIO(self.pdbfilestring) self.pdbfilename = form["PDBID"].value elif form.has_key("PDB") and form["PDB"].filename and form[ "PDBSOURCE"].value == 'UPLOAD': self.pdbfilestring = form["PDB"].value self.pdbfile = StringIO(self.pdbfilestring) self.pdbfilename = sanitizeFileName(form["PDB"].filename) else: raise WebOptionsError( 'You need to specify a pdb ID or upload a pdb file.') if form.has_key("PROPKA"): if not form.has_key('PH'): raise WebOptionsError('Please provide a pH value.') phHelp = 'Please choose a pH between 0.0 and 14.0.' try: ph = float(form["PH"].value) except ValueError: raise WebOptionsError( 'The pH value provided must be a number! ' + phHelp) if ph < 0.0 or ph > 14.0: text = "The entered pH of %.2f is invalid! " % ph text += phHelp raise WebOptionsError(text) self.runoptions['ph'] = ph #build propka options self.runoptions['propkaOptions'] = utilities.createPropkaOptions( ph, True) self.otheroptions['apbs'] = form.has_key("INPUT") self.otheroptions['whitespace'] = form.has_key("WHITESPACE") if self.ff == 'user': if form.has_key("USERFF") and form["USERFF"].filename: self.userfffilename = sanitizeFileName(form["USERFF"].filename) self.userffstring = form["USERFF"].value self.runoptions['userff'] = StringIO(form["USERFF"].value) else: text = "A force field file must be provided if using a user created force field." raise WebOptionsError(text) if form.has_key("USERNAMES") and form["USERNAMES"].filename: self.usernamesfilename = sanitizeFileName( form["USERNAMES"].filename) self.usernamesstring = form["USERNAMES"].value self.runoptions['usernames'] = StringIO( form["USERNAMES"].value) else: text = "A names file must be provided if using a user created force field." raise WebOptionsError(text) if form.has_key("FFOUT") and form["FFOUT"].value != "internal": self.runoptions['ffout'] = form["FFOUT"].value self.runoptions['chain'] = form.has_key("CHAIN") self.runoptions['typemap'] = form.has_key("TYPEMAP") self.runoptions['neutraln'] = form.has_key("NEUTRALN") self.runoptions['neutralc'] = form.has_key("NEUTRALC") if (self.runoptions['neutraln'] or self.runoptions['neutraln']) and \ self.ff != 'parse': raise WebOptionsError( 'Neutral N-terminus and C-terminus require the PARSE forcefield.' ) if form.has_key("LIGAND") and form['LIGAND'].filename: self.ligandfilename = sanitizeFileName(form["LIGAND"].filename) ligandfilestring = form["LIGAND"].value # for Windows and Mac style newline compatibility for pdb2pka ligandfilestring = ligandfilestring.replace('\r\n', '\n') self.ligandfilestring = ligandfilestring.replace('\r', '\n') self.runoptions['ligand'] = StringIO(self.ligandfilestring) if self.pdbfilename[-4:] == ".pdb": self.pqrfilename = "%s.pqr" % self.pdbfilename[:-4] else: self.pqrfilename = "%s.pqr" % self.pdbfilename #Always turn on summary and verbose. self.runoptions['verbose'] = True self.runoptions['selectedExtensions'] = ['summary']