PEATSA/WebApp/JobSubmission.py
def construct(self):
	
		'''Performs all necessary steps for setting up a WebApp job based on the data submitted by a user via the WebApp main page.
		
		This basically involves three steps.
		
			- Creation of a entry for the Job in the WebApp database
			- Outputing the job files uploaded by the user to correct locations
			- Assembing the command line string that will be exectuted when runBackend() is called.
			
		Check the result of errorData()	to see if there were any problems with construction'''
				
		#For each job run a instance of the Job class is created using the JobManager object.
		#This creates the necessary entries in the MySQL database.
		#The Job instance contains info on the job and allows the data stored for the job to be modified.
		self.job = self.jobManager.createJob(self.formData.pdbId(), self.formData.calculations())
		
		#Create the input/output directory names
		try: 
			jobOutputDirectory = self.options.get('WEB APPLICATION', 'jobOutputDirectory')
			jobInputDirectory = self.options.get('WEB APPLICATION', 'jobInputDirectory')
			pKaDataDirectory = self.options.get('WEB APPLICATION', 'pKaDataDirectory')
			backendExecutable = self.options.get('WEB APPLICATION', 'launchScript')
		except 	Core.Exceptions.EnvironmentError, data:
			self._setErrorData(data)
			return
			
		#Get the various IO directories that will be used by the job
		#If the job is to be run on the local host then jobInputDirectory must
		#be the same as webServerDirectory
		webStorageDir = os.path.join(self.webServerDirectory, self.job.identification)
		outputDir = os.path.join(jobOutputDirectory, self.job.identification + '_Out')
		
		if self.formData.isPKACodePresent():
			workingDir = os.path.join(pKaDataDirectory, self.formData.pKaCode())
		else:
			workingDir = os.path.join(jobOutputDirectory, self.job.identification + '_Work')
			
		inputDir = os.path.join(jobInputDirectory, self.job.identification + '_Out')
		os.mkdir(webStorageDir)	
	
		#If this is not a delta pKa calculation we have to write
		#Otherwise write the uploaded/download one to a file
		if not self.formData.isPKACodePresent():
			#To be deprecated
			filename = os.path.join(webStorageDir, '%s.pdb' % self.formData.pdbId())
			stream = self.formData.pdbFileStream()
			self._writeStringToFile(stream.read(), filename)
			pdbFilename = self.formData.pdbFilename()
			#Add structure to db
			stream.seek(0)
			self.job.setStructure(stream.read())
			
			#Check the provided pdb
			error = False
			try:
				structure = self.job.protoolStructure()
			except Exceptions.FileFormatError, data:
				error = True
				self.errorData = {"domain":"PDT.SubmissionDomain",
					"description":"Error in with submission.",
					"detailedDescription": "There is an error in the format of the pdb file",
					"recoverySuggestion": 'Check the file to ensure its format is correct'}
				self.job.setError(description=self.errorData['description'], 
						detailedDescription=self.errorData['detailedDescription'])
				self.job.setState('Finished')
			
			if error is True:
				return

			if structure.hasMissingMainChainAtoms():
				missing = structure.hasMissingMainChainAtoms()
				missing = ", ".join(missing)
				suggestion = "The residues with missing atoms are: %s.<br>" % missing
				suggestion = suggestion + "PEAT-SA requires that all main-chain heavy atoms are present in the structure.<br>"
				suggestion = suggestion + "You could try submitting a fragment of the structure that meets this requirement."
				self.errorData = {"domain":"PDT.SubmissionDomain",
					"description":"Error in submitted pdb structure.",
					"detailedDescription":"The supplied structure is missing main-chain heavy atoms",
					"recoverySuggestion": suggestion}
				self.job.setError(description=self.errorData['description'], 
						detailedDescription=self.errorData['detailedDescription'])
				self.job.setState('Finished')
				return
			elif structure.hasChainBreak():
				suggestion = "PEAT-SA requires that all chains in submitted structures are complete.<br>"
				suggestion = suggestion + "You could try submitting a fragment of the structure that meets this requirement."
				self.errorData = {"domain":"PDT.SubmissionDomain",
					"description":"Error in submitted pdb structure.",
					"detailedDescription":"The supplied structure contains at least one chain-break.",
					"recoverySuggestion": suggestion}
				self.job.setError(description=self.errorData['description'], 
						detailedDescription=self.errorData['detailedDescription'])
				self.job.setState('Finished')
				return
		else:
			pdbFilename = os.path.join(workingDir, self.formData.pdbFilename())	
	
		if self.formData.isLigandPresent():
			filename = os.path.join(webStorageDir, '%s' % self.formData.ligandFilename())
			stream = self.formData.ligandFileStream()
			self._writeStringToFile(stream.read(), filename)
			stream.seek(0)
			self.job.setLigand(stream.read())
			
		#Add email address - This could be just 'Unknown' if none was provided
		self.job.setEmail(self.formData.email())	
	
		#Create the mutation string.
		#This also writes out the mutation file if neccessary
		mutationString = CreateMutationString(self.formData.mutationData, webStorageDir, inputDir, self.job)
		#if the mutationData is a mutation-list check their are actually some mutations in it
		if self.job.isMutationList():
			mutationListFile = self.job.mutationListFile()
			if mutationListFile.numberOfMutants() == 0:
				suggestion = "Return to the submission page and enter some mutation codes in the text-box or upload a file"
				self.errorData = {"domain":"PDT.SubmissionDomain",
					"description":"Error in submitted mutation list.",
					"detailedDescription":"The supplied mutation list contains no mutation codes.",
					"recoverySuggestion": suggestion}
				self.job.setError(description=self.errorData['description'], 
						detailedDescription=self.errorData['detailedDescription'])
				self.job.setState('Finished')
				return
				
		calculationString = CreateCalculationString(self.formData.calculations(), self.formData.ligandFilename())
		
		#Create the run string	
		self.runString = "%s -p %s -w %s -o %s -j %s -v %s %s" % (backendExecutable, os.path.join(inputDir, pdbFilename), 
									workingDir, outputDir, self.job.identification, 
									calculationString, mutationString) 
									
		if self.formData.isIonisableGroupsPresent():
			self.runString += " --ionisableGroups=%s" % self.formData.ionisableGroups()
Performs all necessary steps for setting up a WebApp job based on the data submitted by a user via the WebApp main page.
		
		This basically involves three steps.
		
			- Creation of a entry for the Job in the WebApp database
			- Outputing the job files uploaded by the user to correct locations
			- Assembing the command line string that will be exectuted when runBackend() is called.
			
		Check the result of errorData()	to see if there were any problems with construction
Performs all necessary steps for setting up a WebApp job based on the data submitted by a user via the WebApp main page.
This basically involves three steps.

Creation of a entry for the Job in the WebApp database
Outputing the job files uploaded by the user to correct locations
Assembing the command line string that will be exectuted when runBackend() is called.

Check the result of errorData() to see if there were any problems with construction
Performs all necessary steps for setting up a WebApp job based on the data submitted by a user via the WebApp main page . This basically involves three steps . Creation of a entry for the Job in the WebApp database Outputing the job files uploaded by the user to correct locations Assembing the command line string that will be exectuted when runBackend () is called . Check the result of errorData () to see if there were any problems with construction
def construct(self):
		self.job = self.jobManager.createJob(self.formData.pdbId(), self.formData.calculations())
		try: 
			jobOutputDirectory = self.options.get('WEB APPLICATION', 'jobOutputDirectory')
			jobInputDirectory = self.options.get('WEB APPLICATION', 'jobInputDirectory')
			pKaDataDirectory = self.options.get('WEB APPLICATION', 'pKaDataDirectory')
			backendExecutable = self.options.get('WEB APPLICATION', 'launchScript')
		except 	Core.Exceptions.EnvironmentError, data:
			self._setErrorData(data)
			return
		webStorageDir = os.path.join(self.webServerDirectory, self.job.identification)
		outputDir = os.path.join(jobOutputDirectory, self.job.identification + '_Out')
		if self.formData.isPKACodePresent():
			workingDir = os.path.join(pKaDataDirectory, self.formData.pKaCode())
		else:
			workingDir = os.path.join(jobOutputDirectory, self.job.identification + '_Work')
		inputDir = os.path.join(jobInputDirectory, self.job.identification + '_Out')
		os.mkdir(webStorageDir)	
		if not self.formData.isPKACodePresent():
			filename = os.path.join(webStorageDir, '%s.pdb' % self.formData.pdbId())
			stream = self.formData.pdbFileStream()
			self._writeStringToFile(stream.read(), filename)
			pdbFilename = self.formData.pdbFilename()
			stream.seek(0)
			self.job.setStructure(stream.read())
			error = False
			try:
				structure = self.job.protoolStructure()
			except Exceptions.FileFormatError, data:
				error = True
				self.errorData = {"domain":"PDT.SubmissionDomain",
					"description":"Error in with submission.",
					"detailedDescription": "There is an error in the format of the pdb file",
					"recoverySuggestion": 'Check the file to ensure its format is correct'}
				self.job.setError(description=self.errorData['description'], 
						detailedDescription=self.errorData['detailedDescription'])
				self.job.setState('Finished')
			if error is True:
				return
			if structure.hasMissingMainChainAtoms():
				missing = structure.hasMissingMainChainAtoms()
				missing = ", ".join(missing)
				suggestion = "The residues with missing atoms are: %s.<br>" % missing
				suggestion = suggestion + "PEAT-SA requires that all main-chain heavy atoms are present in the structure.<br>"
				suggestion = suggestion + "You could try submitting a fragment of the structure that meets this requirement."
				self.errorData = {"domain":"PDT.SubmissionDomain",
					"description":"Error in submitted pdb structure.",
					"detailedDescription":"The supplied structure is missing main-chain heavy atoms",
					"recoverySuggestion": suggestion}
				self.job.setError(description=self.errorData['description'], 
						detailedDescription=self.errorData['detailedDescription'])
				self.job.setState('Finished')
				return
			elif structure.hasChainBreak():
				suggestion = "PEAT-SA requires that all chains in submitted structures are complete.<br>"
				suggestion = suggestion + "You could try submitting a fragment of the structure that meets this requirement."
				self.errorData = {"domain":"PDT.SubmissionDomain",
					"description":"Error in submitted pdb structure.",
					"detailedDescription":"The supplied structure contains at least one chain-break.",
					"recoverySuggestion": suggestion}
				self.job.setError(description=self.errorData['description'], 
						detailedDescription=self.errorData['detailedDescription'])
				self.job.setState('Finished')
				return
		else:
			pdbFilename = os.path.join(workingDir, self.formData.pdbFilename())	
		if self.formData.isLigandPresent():
			filename = os.path.join(webStorageDir, '%s' % self.formData.ligandFilename())
			stream = self.formData.ligandFileStream()
			self._writeStringToFile(stream.read(), filename)
			stream.seek(0)
			self.job.setLigand(stream.read())
		self.job.setEmail(self.formData.email())	
		mutationString = CreateMutationString(self.formData.mutationData, webStorageDir, inputDir, self.job)
		if self.job.isMutationList():
			mutationListFile = self.job.mutationListFile()
			if mutationListFile.numberOfMutants() == 0:
				suggestion = "Return to the submission page and enter some mutation codes in the text-box or upload a file"
				self.errorData = {"domain":"PDT.SubmissionDomain",
					"description":"Error in submitted mutation list.",
					"detailedDescription":"The supplied mutation list contains no mutation codes.",
					"recoverySuggestion": suggestion}
				self.job.setError(description=self.errorData['description'], 
						detailedDescription=self.errorData['detailedDescription'])
				self.job.setState('Finished')
				return
		calculationString = CreateCalculationString(self.formData.calculations(), self.formData.ligandFilename())
		self.runString = "%s -p %s -w %s -o %s -j %s -v %s %s" % (backendExecutable, os.path.join(inputDir, pdbFilename), 
									workingDir, outputDir, self.job.identification, 
									calculationString, mutationString) 
		if self.formData.isIonisableGroupsPresent():
			self.runString += " --ionisableGroups=%s" % self.formData.ionisableGroups()
def construct ( self ) : self . job = self . jobManager . createJob ( self . formData . pdbId ( ) , self . formData . calculations ( ) ) try : jobOutputDirectory = self . options . get ( 'WEB APPLICATION' , 'jobOutputDirectory' ) jobInputDirectory = self . options . get ( 'WEB APPLICATION' , 'jobInputDirectory' ) pKaDataDirectory = self . options . get ( 'WEB APPLICATION' , 'pKaDataDirectory' ) backendExecutable = self . options . get ( 'WEB APPLICATION' , 'launchScript' ) except Core . Exceptions . EnvironmentError , data : self . _setErrorData ( data ) return webStorageDir = os . path . join ( self . webServerDirectory , self . job . identification ) outputDir = os . path . join ( jobOutputDirectory , self . job . identification + '_Out' ) if self . formData . isPKACodePresent ( ) : workingDir = os . path . join ( pKaDataDirectory , self . formData . pKaCode ( ) ) else : workingDir = os . path . join ( jobOutputDirectory , self . job . identification + '_Work' ) inputDir = os . path . join ( jobInputDirectory , self . job . identification + '_Out' ) os . mkdir ( webStorageDir ) if not self . formData . isPKACodePresent ( ) : filename = os . path . join ( webStorageDir , '%s.pdb' % self . formData . pdbId ( ) ) stream = self . formData . pdbFileStream ( ) self . _writeStringToFile ( stream . read ( ) , filename ) pdbFilename = self . formData . pdbFilename ( ) stream . seek ( 0 ) self . job . setStructure ( stream . read ( ) ) error = False try : structure = self . job . protoolStructure ( ) except Exceptions . FileFormatError , data : error = True self . errorData = { "domain" : "PDT.SubmissionDomain" , "description" : "Error in with submission." , "detailedDescription" : "There is an error in the format of the pdb file" , "recoverySuggestion" : 'Check the file to ensure its format is correct' } self . job . setError ( description = self . errorData [ 'description' ] , detailedDescription = self . errorData [ 'detailedDescription' ] ) self . job . setState ( 'Finished' ) if error is True : return if structure . hasMissingMainChainAtoms ( ) : missing = structure . hasMissingMainChainAtoms ( ) missing = ", " . join ( missing ) suggestion = "The residues with missing atoms are: %s.<br>" % missing suggestion = suggestion + "PEAT-SA requires that all main-chain heavy atoms are present in the structure.<br>" suggestion = suggestion + "You could try submitting a fragment of the structure that meets this requirement." self . errorData = { "domain" : "PDT.SubmissionDomain" , "description" : "Error in submitted pdb structure." , "detailedDescription" : "The supplied structure is missing main-chain heavy atoms" , "recoverySuggestion" : suggestion } self . job . setError ( description = self . errorData [ 'description' ] , detailedDescription = self . errorData [ 'detailedDescription' ] ) self . job . setState ( 'Finished' ) return elif structure . hasChainBreak ( ) : suggestion = "PEAT-SA requires that all chains in submitted structures are complete.<br>" suggestion = suggestion + "You could try submitting a fragment of the structure that meets this requirement." self . errorData = { "domain" : "PDT.SubmissionDomain" , "description" : "Error in submitted pdb structure." , "detailedDescription" : "The supplied structure contains at least one chain-break." , "recoverySuggestion" : suggestion } self . job . setError ( description = self . errorData [ 'description' ] , detailedDescription = self . errorData [ 'detailedDescription' ] ) self . job . setState ( 'Finished' ) return else : pdbFilename = os . path . join ( workingDir , self . formData . pdbFilename ( ) ) if self . formData . isLigandPresent ( ) : filename = os . path . join ( webStorageDir , '%s' % self . formData . ligandFilename ( ) ) stream = self . formData . ligandFileStream ( ) self . _writeStringToFile ( stream . read ( ) , filename ) stream . seek ( 0 ) self . job . setLigand ( stream . read ( ) ) self . job . setEmail ( self . formData . email ( ) ) mutationString = CreateMutationString ( self . formData . mutationData , webStorageDir , inputDir , self . job ) if self . job . isMutationList ( ) : mutationListFile = self . job . mutationListFile ( ) if mutationListFile . numberOfMutants ( ) == 0 : suggestion = "Return to the submission page and enter some mutation codes in the text-box or upload a file" self . errorData = { "domain" : "PDT.SubmissionDomain" , "description" : "Error in submitted mutation list." , "detailedDescription" : "The supplied mutation list contains no mutation codes." , "recoverySuggestion" : suggestion } self . job . setError ( description = self . errorData [ 'description' ] , detailedDescription = self . errorData [ 'detailedDescription' ] ) self . job . setState ( 'Finished' ) return calculationString = CreateCalculationString ( self . formData . calculations ( ) , self . formData . ligandFilename ( ) ) self . runString = "%s -p %s -w %s -o %s -j %s -v %s %s" % ( backendExecutable , os . path . join ( inputDir , pdbFilename ) , workingDir , outputDir , self . job . identification , calculationString , mutationString ) if self . formData . isIonisableGroupsPresent ( ) : self . runString += " --ionisableGroups=%s" % self . formData . ionisableGroups ( )
Performs all necessary steps for setting up a WebApp job based on the data submitted by a user via the WebApp main page.
Performs all necessary steps for setting up a WebApp job based on the data submitted by a user via the WebApp main page .
'''Performs all necessary steps for setting up a WebApp job based on the data submitted by a user via the WebApp main page.
		
		This basically involves three steps.
		
			- Creation of a entry for the Job in the WebApp database
			- Outputing the job files uploaded by the user to correct locations
			- Assembing the command line string that will be exectuted when runBackend() is called.
			
		Check the result of errorData()	to see if there were any problems with construction''' #For each job run a instance of the Job class is created using the JobManager object. #This creates the necessary entries in the MySQL database. #The Job instance contains info on the job and allows the data stored for the job to be modified. #Create the input/output directory names #Get the various IO directories that will be used by the job #If the job is to be run on the local host then jobInputDirectory must #be the same as webServerDirectory #If this is not a delta pKa calculation we have to write #Otherwise write the uploaded/download one to a file #To be deprecated #Add structure to db #Check the provided pdb #Add email address - This could be just 'Unknown' if none was provided #Create the mutation string. #This also writes out the mutation file if neccessary #if the mutationData is a mutation-list check their are actually some mutations in it #Create the run string	
self