PEATSA/Core/Utilities.py
def CleanWHATIF(inputFile, outputFile, removeWater=True, removeLigand=True, removeAltLoc=True, addHydrogens=True, correct=True):

	'''Cleans a PDB using WHAT-IF		

	Errors: 
		Raises an exception if the inputFile is not a valid PDB file.'''

	import pKarun.WI_tools, Protool
	
	#First try to load the pdb using protool.
	#If its not valid 
	try:
		pdb = Protool.structureIO()
		pdb.readpdb(inputFile)
	except Exception, data:	
		raise Exceptions.FileFormatError, 'Format of specified PDB file %s not valid.\nUnderlying error - %s' % (inputFile, data)

	try:
		logfile = None
		
		#Create the WHATIF command script
		command = WhatIfCommandBoilerPlate(inputFile)
		
		if removeWater is True:
			command = command + ' %DELWAT \n'
		if removeLigand is True:
			command = command + ' %DELLIG \n'
		if addHydrogens is True:
			command = command + ' %delhyd tot 0\n'
		if correct is True:
			command = command + ' %corall \n N\n'	
		if addHydrogens is True:
			command = command + ' setwif 339 1 \n %addhyd tot 0 \n tot 0\n'
			
		makeMoleculeCommand, whatIfOutputFile = WhatIfMakeMoleculeCommand(inputFile)
		command = command + makeMoleculeCommand
		
		#RunWhatIF - Different command needed if hydrogens are to be added
		if addHydrogens:
			logfile, newPDB = pKarun.WI_tools.RunWI(command,[whatIfOutputFile],None,[inputFile,'HTOP'])
		else:	
			logfile, newPDB = pKarun.WI_tools.RunWI(command,[whatIfOutputFile],None,[inputFile])

		#logfile is the output. newPDB is a dictionary with one entry.
		#The key is the new pdb name (relative and useless).
		#The value are the lines of the new pdb
		#Write the cleaned pdb to specified output location
		stream = open(outputFile, 'w+')		
		stream.writelines(newPDB.values()[0])
		stream.close()

		#Protool ignores altlocs so we can use it to remove them 
		if removeAltLoc is True:
			pdb = Protool.structureIO()
			pdb.readpdb(outputFile)
			pdb.writepdb(outputFile)
		
	except BaseException, data:
		print 'Encountered an exception cleaning pdb %s' % inputFile
		if logfile is not None:
			for line in logfile:
				print line
		
		raise
Cleans a PDB using WHAT-IF		

	Errors: 
		Raises an exception if the inputFile is not a valid PDB file.
Cleans a PDB using WHAT-IF
Errors:
Raises an exception if the inputFile is not a valid PDB file.
Cleans a PDB using WHAT - IF Errors : Raises an exception if the inputFile is not a valid PDB file .
def CleanWHATIF(inputFile, outputFile, removeWater=True, removeLigand=True, removeAltLoc=True, addHydrogens=True, correct=True):
	import pKarun.WI_tools, Protool
	try:
		pdb = Protool.structureIO()
		pdb.readpdb(inputFile)
	except Exception, data:	
		raise Exceptions.FileFormatError, 'Format of specified PDB file %s not valid.\nUnderlying error - %s' % (inputFile, data)
	try:
		logfile = None
		command = WhatIfCommandBoilerPlate(inputFile)
		if removeWater is True:
			command = command + ' %DELWAT \n'
		if removeLigand is True:
			command = command + ' %DELLIG \n'
		if addHydrogens is True:
			command = command + ' %delhyd tot 0\n'
		if correct is True:
			command = command + ' %corall \n N\n'	
		if addHydrogens is True:
			command = command + ' setwif 339 1 \n %addhyd tot 0 \n tot 0\n'
		makeMoleculeCommand, whatIfOutputFile = WhatIfMakeMoleculeCommand(inputFile)
		command = command + makeMoleculeCommand
		if addHydrogens:
			logfile, newPDB = pKarun.WI_tools.RunWI(command,[whatIfOutputFile],None,[inputFile,'HTOP'])
		else:	
			logfile, newPDB = pKarun.WI_tools.RunWI(command,[whatIfOutputFile],None,[inputFile])
		stream = open(outputFile, 'w+')		
		stream.writelines(newPDB.values()[0])
		stream.close()
		if removeAltLoc is True:
			pdb = Protool.structureIO()
			pdb.readpdb(outputFile)
			pdb.writepdb(outputFile)
	except BaseException, data:
		print 'Encountered an exception cleaning pdb %s' % inputFile
		if logfile is not None:
			for line in logfile:
				print line
		raise
def CleanWHATIF ( inputFile , outputFile , removeWater = True , removeLigand = True , removeAltLoc = True , addHydrogens = True , correct = True ) : import pKarun . WI_tools , Protool try : pdb = Protool . structureIO ( ) pdb . readpdb ( inputFile ) except Exception , data : raise Exceptions . FileFormatError , 'Format of specified PDB file %s not valid.\nUnderlying error - %s' % ( inputFile , data ) try : logfile = None command = WhatIfCommandBoilerPlate ( inputFile ) if removeWater is True : command = command + ' %DELWAT \n' if removeLigand is True : command = command + ' %DELLIG \n' if addHydrogens is True : command = command + ' %delhyd tot 0\n' if correct is True : command = command + ' %corall \n N\n' if addHydrogens is True : command = command + ' setwif 339 1 \n %addhyd tot 0 \n tot 0\n' makeMoleculeCommand , whatIfOutputFile = WhatIfMakeMoleculeCommand ( inputFile ) command = command + makeMoleculeCommand if addHydrogens : logfile , newPDB = pKarun . WI_tools . RunWI ( command , [ whatIfOutputFile ] , None , [ inputFile , 'HTOP' ] ) else : logfile , newPDB = pKarun . WI_tools . RunWI ( command , [ whatIfOutputFile ] , None , [ inputFile ] ) stream = open ( outputFile , 'w+' ) stream . writelines ( newPDB . values ( ) [ 0 ] ) stream . close ( ) if removeAltLoc is True : pdb = Protool . structureIO ( ) pdb . readpdb ( outputFile ) pdb . writepdb ( outputFile ) except BaseException , data : print 'Encountered an exception cleaning pdb %s' % inputFile if logfile is not None : for line in logfile : print line raise
Cleans a PDB using WHAT-IF
Errors:
Raises an exception if the inputFile is not a valid PDB file.
Cleans a PDB using WHAT - IF Errors : Raises an exception if the inputFile is not a valid PDB file .
'''Cleans a PDB using WHAT-IF		

	Errors: 
		Raises an exception if the inputFile is not a valid PDB file.''' #First try to load the pdb using protool. #If its not valid  #Create the WHATIF command script #RunWhatIF - Different command needed if hydrogens are to be added #logfile is the output. newPDB is a dictionary with one entry. #The key is the new pdb name (relative and useless). #The value are the lines of the new pdb #Write the cleaned pdb to specified output location #Protool ignores altlocs so we can use it to remove them 
inputFile
outputFile
removeWater
removeLigand
removeAltLoc
addHydrogens
correct