PEATSA/Core/Programs.py
def deltaStability(self, comparePDBs=[], verbose=False):
	
		'''Calculate the difference in stability between the source pdb and the compare pbds
		
		Parameters
			comparePDBs - A list of paths to PDB files.
				All the pdbs in this list will be compared to the sourcePDB.
				The names of the compare pdbs are expected to conform to the following
				.....
				(FIXME: Possibly only have to be of a certain format to do a 'mutantStability' run?)
		
		Exceptions:
			Raises an Exceptions.UFFBAPSError if the source pdb does not exist.
			Raises an Exceptions.UFFBAPSError if any of the comparePDBS does not exist.
			However the calculation is performed for all existing pdbs first.'''
	
				
		#If there are no compare pdbs supplied raise an exception
		if len(comparePDBs) == 0:
			raise Exceptions.StabilityError, "Unable to perform stability calculation - No mutants supplied"
	
		#Copy the wildType to the working dir
		pdbName = os.path.split(self.sourcePDB)[1]
		#Uffbaps requires the pdb to have a .pdb extension - check this
		components = os.path.splitext(pdbName)
		if components[1] != 'pdb':
			pdbName = '%s.pdb' % components[0]
			
		if self.environment.isRoot():
			shutil.copyfile(self.sourcePDB, os.path.join(self.directoryPath, pdbName))
		self.environment.wait()	
		
		#The run file name
		runFile = os.path.join(self.directoryPath, "run%d.txt" % self.environment.rank())
		outputFile = os.path.join(self.directoryPath, "output%d.txt" % self.environment.rank())
		outputStream = open(outputFile, "a+")
		
		#The executable
		executable = os.path.join(self.executablePath, "Uffbaps")
		
		self.environment.output(('\n[STABILITY] Running stability comparison between %s and %d mutants' 
			% (os.path.split(self.sourcePDB)[1], len(comparePDBs))))
		self.environment.output('[STABILITY] Using Uffbaps at %s' % self.executablePath)
		self.environment.output('[STABILITY] Beginning stability calculation in %s' % self.directoryPath)
		
		#Force output of last print line - required when using ","
		sys.stdout.flush()
	
		#Variables for informing user of progress
		ten = int(len(comparePDBs)/10.0)
		#Avoid module zero if their are less than 10 pbds
		if ten == 0:
			ten = 1
		count = 0
	
		#Accumulate the results for each mutation into this list
		#It will be used at the end to create a matrix
		rows = []
		
		#Ask the environment to split the comparePDB array if necessary 
		#That is if this is a parallel run
		comparePDBs = self.environment.splitArray(comparePDBs)
		for pdbFile in comparePDBs:
			if verbose:
				self.environment.output('[STABILITY] Mutant %s' % os.path.split(pdbFile)[1], rootOnly=False)
			
			#Copy the mutant to the working dir
			compareName = os.path.split(pdbFile)[1]
			shutil.copyfile(pdbFile, os.path.join(self.directoryPath, compareName))
			
			#Create the run file 
			self._writeDeltaStabilityRunFile(pdbName, compareName, filename=runFile)
			
			#Run
			process = subprocess.Popen([executable, runFile], cwd=self.directoryPath, stdout=outputStream)
			process.wait()
		
			#Get the results
			outputStream.seek(0)
			lines = outputStream.readlines()
			result = lines[-1:]
			
			try:
				#If an exception is raised here it means something unexpected
				#was returned by UFFBAPS
				components = self._chopDeltaStabilityResultLine(result[0])
				
				#Add the name of the mutation and then the stability values 
				#to the 'rows' variable
				row = [os.path.splitext(compareName)[0]]
				row.extend(components)	
				rows.append(row)
				
				#Get rid of the mutant pdb file we copied
				os.remove(os.path.join(self.directoryPath, compareName))
				
				if not verbose:
					count = count + 1
					if count%ten == 0:
						#A ugly space is left if print is used
						sys.stdout.write(".")
						sys.stdout.flush()
				else:
					self.environment.output(
						'[STABILITY] %s' % zip(UFFBAPS.stabilityResultsHeaders, components), 
						rootOnly=False)		

			except BaseException:
				self.environment.output(
					'[STABILITY] Unable to parse unexpected UFFBAPS output\n%s\n' % lines, 
					rootOnly=False,
					stream=sys.stderr)
				self.environment.output(
					'[STABILITY] Skipping mutant %s\n' % os.path.split(pdbFile)[1], 
					rootOnly=False,
					stream=sys.stderr)
	
			#Reset the stream
			outputStream.seek(0)
			outputStream.truncate()
			
		outputStream.close()
		#This is required in order to catch if any the processes exited the 
		#above loop due to an exception	
		self.environment.wait()	
		#Combine all the rows
		rows = self.environment.combineArray(rows)
		
		if self.environment.isRoot():
			headers = ['Mutations']
			headers.extend(UFFBAPS.stabilityResultsHeaders)
			self.resultsMatrix = Matrix.PEATSAMatrix(rows=rows, headers=headers, name="Stability")
	
			#Add some comments
			comments = stabilityCommentStrings[:]
			date = datetime.datetime.today()
			comments.insert(1, "Generated  by PEAT_SA on %s" % date.strftime('%A %d/%m/%Y %H:%M:%S %Z'))
Calculate the difference in stability between the source pdb and the compare pbds
		
		Parameters
			comparePDBs - A list of paths to PDB files.
				All the pdbs in this list will be compared to the sourcePDB.
				The names of the compare pdbs are expected to conform to the following
				.....
				(FIXME: Possibly only have to be of a certain format to do a 'mutantStability' run?)
		
		Exceptions:
			Raises an Exceptions.UFFBAPSError if the source pdb does not exist.
			Raises an Exceptions.UFFBAPSError if any of the comparePDBS does not exist.
			However the calculation is performed for all existing pdbs first.
Calculate the difference in stability between the source pdb and the compare pbds
Parameters
comparePDBs - A list of paths to PDB files.
All the pdbs in this list will be compared to the sourcePDB.
The names of the compare pdbs are expected to conform to the following

(FIXME: Possibly only have to be of a certain format to do a 'mutantStability' run?)

Raises an Exceptions.UFFBAPSError if the source pdb does not exist.
Raises an Exceptions.UFFBAPSError if any of the comparePDBS does not exist.
However the calculation is performed for all existing pdbs first.
Calculate the difference in stability between the source pdb and the compare pbds Parameters comparePDBs - A list of paths to PDB files . All the pdbs in this list will be compared to the sourcePDB . The names of the compare pdbs are expected to conform to the following ( FIXME : Possibly only have to be of a certain format to do a ' mutantStability ' run? ) Raises an Exceptions . UFFBAPSError if the source pdb does not exist . Raises an Exceptions . UFFBAPSError if any of the comparePDBS does not exist . However the calculation is performed for all existing pdbs first .
def deltaStability(self, comparePDBs=[], verbose=False):
		if len(comparePDBs) == 0:
			raise Exceptions.StabilityError, "Unable to perform stability calculation - No mutants supplied"
		pdbName = os.path.split(self.sourcePDB)[1]
		components = os.path.splitext(pdbName)
		if components[1] != 'pdb':
			pdbName = '%s.pdb' % components[0]
		if self.environment.isRoot():
			shutil.copyfile(self.sourcePDB, os.path.join(self.directoryPath, pdbName))
		self.environment.wait()	
		runFile = os.path.join(self.directoryPath, "run%d.txt" % self.environment.rank())
		outputFile = os.path.join(self.directoryPath, "output%d.txt" % self.environment.rank())
		outputStream = open(outputFile, "a+")
		executable = os.path.join(self.executablePath, "Uffbaps")
		self.environment.output(('\n[STABILITY] Running stability comparison between %s and %d mutants' 
			% (os.path.split(self.sourcePDB)[1], len(comparePDBs))))
		self.environment.output('[STABILITY] Using Uffbaps at %s' % self.executablePath)
		self.environment.output('[STABILITY] Beginning stability calculation in %s' % self.directoryPath)
		sys.stdout.flush()
		ten = int(len(comparePDBs)/10.0)
		if ten == 0:
			ten = 1
		count = 0
		rows = []
		comparePDBs = self.environment.splitArray(comparePDBs)
		for pdbFile in comparePDBs:
			if verbose:
				self.environment.output('[STABILITY] Mutant %s' % os.path.split(pdbFile)[1], rootOnly=False)
			compareName = os.path.split(pdbFile)[1]
			shutil.copyfile(pdbFile, os.path.join(self.directoryPath, compareName))
			self._writeDeltaStabilityRunFile(pdbName, compareName, filename=runFile)
			process = subprocess.Popen([executable, runFile], cwd=self.directoryPath, stdout=outputStream)
			process.wait()
			outputStream.seek(0)
			lines = outputStream.readlines()
			result = lines[-1:]
			try:
				components = self._chopDeltaStabilityResultLine(result[0])
				row = [os.path.splitext(compareName)[0]]
				row.extend(components)	
				rows.append(row)
				os.remove(os.path.join(self.directoryPath, compareName))
				if not verbose:
					count = count + 1
					if count%ten == 0:
						sys.stdout.write(".")
						sys.stdout.flush()
				else:
					self.environment.output(
						'[STABILITY] %s' % zip(UFFBAPS.stabilityResultsHeaders, components), 
						rootOnly=False)		
			except BaseException:
				self.environment.output(
					'[STABILITY] Unable to parse unexpected UFFBAPS output\n%s\n' % lines, 
					rootOnly=False,
					stream=sys.stderr)
				self.environment.output(
					'[STABILITY] Skipping mutant %s\n' % os.path.split(pdbFile)[1], 
					rootOnly=False,
					stream=sys.stderr)
			outputStream.seek(0)
			outputStream.truncate()
		outputStream.close()
		self.environment.wait()	
		rows = self.environment.combineArray(rows)
		if self.environment.isRoot():
			headers = ['Mutations']
			headers.extend(UFFBAPS.stabilityResultsHeaders)
			self.resultsMatrix = Matrix.PEATSAMatrix(rows=rows, headers=headers, name="Stability")
			comments = stabilityCommentStrings[:]
			date = datetime.datetime.today()
			comments.insert(1, "Generated  by PEAT_SA on %s" % date.strftime('%A %d/%m/%Y %H:%M:%S %Z'))
def deltaStability ( self , comparePDBs = [ ] , verbose = False ) : if len ( comparePDBs ) == 0 : raise Exceptions . StabilityError , "Unable to perform stability calculation - No mutants supplied" pdbName = os . path . split ( self . sourcePDB ) [ 1 ] components = os . path . splitext ( pdbName ) if components [ 1 ] != 'pdb' : pdbName = '%s.pdb' % components [ 0 ] if self . environment . isRoot ( ) : shutil . copyfile ( self . sourcePDB , os . path . join ( self . directoryPath , pdbName ) ) self . environment . wait ( ) runFile = os . path . join ( self . directoryPath , "run%d.txt" % self . environment . rank ( ) ) outputFile = os . path . join ( self . directoryPath , "output%d.txt" % self . environment . rank ( ) ) outputStream = open ( outputFile , "a+" ) executable = os . path . join ( self . executablePath , "Uffbaps" ) self . environment . output ( ( '\n[STABILITY] Running stability comparison between %s and %d mutants' % ( os . path . split ( self . sourcePDB ) [ 1 ] , len ( comparePDBs ) ) ) ) self . environment . output ( '[STABILITY] Using Uffbaps at %s' % self . executablePath ) self . environment . output ( '[STABILITY] Beginning stability calculation in %s' % self . directoryPath ) sys . stdout . flush ( ) ten = int ( len ( comparePDBs ) / 10.0 ) if ten == 0 : ten = 1 count = 0 rows = [ ] comparePDBs = self . environment . splitArray ( comparePDBs ) for pdbFile in comparePDBs : if verbose : self . environment . output ( '[STABILITY] Mutant %s' % os . path . split ( pdbFile ) [ 1 ] , rootOnly = False ) compareName = os . path . split ( pdbFile ) [ 1 ] shutil . copyfile ( pdbFile , os . path . join ( self . directoryPath , compareName ) ) self . _writeDeltaStabilityRunFile ( pdbName , compareName , filename = runFile ) process = subprocess . Popen ( [ executable , runFile ] , cwd = self . directoryPath , stdout = outputStream ) process . wait ( ) outputStream . seek ( 0 ) lines = outputStream . readlines ( ) result = lines [ - 1 : ] try : components = self . _chopDeltaStabilityResultLine ( result [ 0 ] ) row = [ os . path . splitext ( compareName ) [ 0 ] ] row . extend ( components ) rows . append ( row ) os . remove ( os . path . join ( self . directoryPath , compareName ) ) if not verbose : count = count + 1 if count % ten == 0 : sys . stdout . write ( "." ) sys . stdout . flush ( ) else : self . environment . output ( '[STABILITY] %s' % zip ( UFFBAPS . stabilityResultsHeaders , components ) , rootOnly = False ) except BaseException : self . environment . output ( '[STABILITY] Unable to parse unexpected UFFBAPS output\n%s\n' % lines , rootOnly = False , stream = sys . stderr ) self . environment . output ( '[STABILITY] Skipping mutant %s\n' % os . path . split ( pdbFile ) [ 1 ] , rootOnly = False , stream = sys . stderr ) outputStream . seek ( 0 ) outputStream . truncate ( ) outputStream . close ( ) self . environment . wait ( ) rows = self . environment . combineArray ( rows ) if self . environment . isRoot ( ) : headers = [ 'Mutations' ] headers . extend ( UFFBAPS . stabilityResultsHeaders ) self . resultsMatrix = Matrix . PEATSAMatrix ( rows = rows , headers = headers , name = "Stability" ) comments = stabilityCommentStrings [ : ] date = datetime . datetime . today ( ) comments . insert ( 1 , "Generated  by PEAT_SA on %s" % date . strftime ( '%A %d/%m/%Y %H:%M:%S %Z' ) )
Calculate the difference in stability between the source pdb and the compare pbds
Parameters
comparePDBs - A list of paths to PDB files.
Calculate the difference in stability between the source pdb and the compare pbds Parameters comparePDBs - A list of paths to PDB files .
'''Calculate the difference in stability between the source pdb and the compare pbds
		
		Parameters
			comparePDBs - A list of paths to PDB files.
				All the pdbs in this list will be compared to the sourcePDB.
				The names of the compare pdbs are expected to conform to the following
				.....
				(FIXME: Possibly only have to be of a certain format to do a 'mutantStability' run?)
		
		Exceptions:
			Raises an Exceptions.UFFBAPSError if the source pdb does not exist.
			Raises an Exceptions.UFFBAPSError if any of the comparePDBS does not exist.
			However the calculation is performed for all existing pdbs first.''' #If there are no compare pdbs supplied raise an exception #Copy the wildType to the working dir #Uffbaps requires the pdb to have a .pdb extension - check this #The run file name #The executable #Force output of last print line - required when using "," #Variables for informing user of progress #Avoid module zero if their are less than 10 pbds #Accumulate the results for each mutation into this list #It will be used at the end to create a matrix #Ask the environment to split the comparePDB array if necessary  #That is if this is a parallel run #Copy the mutant to the working dir #Create the run file  #Run #Get the results #If an exception is raised here it means something unexpected #was returned by UFFBAPS #Add the name of the mutation and then the stability values  #to the 'rows' variable #Get rid of the mutant pdb file we copied #A ugly space is left if print is used #Reset the stream #This is required in order to catch if any the processes exited the  #above loop due to an exception	 #Combine all the rows #Add some comments
self
comparePDBs
verbose