pKaTool/Ghosts/Chemical_shift_md.py
def calculateCSP(self):
		'''
		calculates potentials of all N, C (N and H) atoms from num1 and num2 side chains, protein, water and Cl
		'''
		
		fd_progress = open("progress.log", 'a');
		fileFirst = self.pdb + '.pdb.' + str(self.start)
		coordMol, coordSol, coordCl = self.parseCoord(fileFirst)
		resNumsMol = coordMol.keys()
		resNumsMol.sort()
		resNumsSol = coordSol.keys()
		resNumsSol.sort()
		resNumsCl = coordCl.keys()
		resNumsCl.sort()
		chargeDict = self.parseCharges()
		diel = self.diel
		if len(self.resNums) > 0:
			resCalculate = self.resNums
		else:
			resCalculate = resNumsMol
		for resNumMol in resCalculate:
			if resNumMol == 1: continue 
			if 'H' not in coordMol[resNumMol].keys(): continue #PROLINE
			linesN = []
			linesH = []
			fileNameN = 'energyN%s.txt'%resNumMol
			fileNameH = 'energyH%s.txt'%resNumMol
			if (os.path.isfile(fileNameN)) and (os.path.isfile(fileNameH)): continue
			print >> fd_progress, "\nPredicting ghost titrations for residue %d ...\n"%(resNumMol)
			fdN = open(fileNameN, 'a')
			fdH = open(fileNameH, 'a')
			#N
			ENside = 0
			ENback = 0
			ENsol = 0
			ENcl = 0
			ENtotal =0#does not include Cl
			#H
			EHside = 0
			EHback = 0
			EHsol = 0
			EHcl = 0
			EHtotal =0#does not include Cl
			counter = 1
			structNum = self.start
			while structNum <= self.end:
				fileName = self.pdb + '.pdb.' + str(structNum)
				filePath = os.path.join(os.getcwd(), fileName)
				if not (os.path.isfile(fileName) or os.path.isfile(filePath)):
					print "WARNING: PDB file %s does not exist "%fileName
					structNum += self.step
					continue
				coordMol, coordSol, coordCl = self.parseCoord(fileName)
				print >> fd_progress, "\tParsing coordinates from structure %s..."%(fileName)
				for resNum in resNumsMol:
					for atomName in coordMol[resNum].keys():
						if (atomName in backboneAtoms) and (abs(resNum-resNumMol)<2): continue#too close to backbone atom
						#print resNum, atomName
						#if not atomName in chargeDict[resNum].keys():
						#	print 'Atom %s doesnt exist in topology file'%atomName
						#	continue #GLU charged doesn't have NE2 in top file
						try:
							coordN = coordMol[resNumMol]['N']
							coordC = coordMol[resNumMol-1]['C']
							coordH = coordMol[resNumMol]['H']
							distN, cosAngleN = getDistanceAngle(coordN,
								coordC, coordMol[resNum][atomName])
						except:
							continue
						try:
							distH, cosAngleH = getDistanceAngle(coordH,
								coordN, coordMol[resNum][atomName])
						except:
							continue
						charge = chargeDict[resNum][atomName]
						EN = fieldCoulomb(distN, cosAngleN, charge) * nsp['N'] / diel
						EH = fieldCoulomb(distH, cosAngleH, charge) * nsp['H'] / diel
						if atomName in backboneAtoms:
							ENback+=EN
							EHback+=EH
						else:
							ENside+=EN
							EHside+=EH
						ENtotal+=EN
						EHtotal+=EH
				
				for resNum in resNumsSol:
					for atomName in coordSol[resNum].keys():
						try:
							distN, cosAngleN = getDistanceAngle(coordN,
								coordC, coordSol[resNum][atomName])
						except:
							continue
						try:
							distH, cosAngleH = getDistanceAngle(coordH,
								coordN, coordSol[resNum][atomName])
						except:
							continue
						charge = chargesSol[atomName]
						EN = fieldCoulomb(distN, cosAngleN, charge) * nsp['N'] / diel
						EH = fieldCoulomb(distH, cosAngleH, charge) * nsp['H'] / diel
						ENsol+=EN
						EHsol+=EH
						ENtotal+=EN
						EHtotal+=EH
				
				for resNum in resNumsCl:
					try:
						distN, cosAngleN = getDistanceAngle(coordN,
							coordC, coordCl[resNum])
					except:
						continue
					try:
						distH, cosAngleH = getDistanceAngle(coordH,
							coordN, coordCl[resNum])
					except:
						continue
					charge = chargesSol['Cl-']
					ENcl+=fieldCoulomb(distN, cosAngleN, charge) * nsp['N'] / diel
					EHcl+=fieldCoulomb(distH, cosAngleH, charge) * nsp['H'] / diel
								
				lineN = '%5d  %10.6f  %10.6f  %10.6f  %10.6f  %10.6f\n'%(structNum, ENside/counter, ENback/counter, ENsol/counter, ENcl/counter, ENtotal/counter)
				fdN.write(lineN)
				lineH = '%5d  %10.6f  %10.6f  %10.6f  %10.6f  %10.6f\n'%(structNum, EHside/counter, EHback/counter, EHsol/counter, EHcl/counter, EHtotal/counter)
				fdH.write(lineH)
				structNum += self.step
				counter+=1
			fdN.close()
			fdH.close()
			print >> fd_progress, "\nDone...."
		fd_progress.close()
		return

		calculates potentials of all N, C (N and H) atoms from num1 and num2 side chains, protein, water and Cl
		
calculates potentials of all N, C (N and H) atoms from num1 and num2 side chains, protein, water and Cl
calculates potentials of all N C ( N and H ) atoms from num1 and num2 side chains protein water and Cl
def calculateCSP(self):
		fd_progress = open("progress.log", 'a');
		fileFirst = self.pdb + '.pdb.' + str(self.start)
		coordMol, coordSol, coordCl = self.parseCoord(fileFirst)
		resNumsMol = coordMol.keys()
		resNumsMol.sort()
		resNumsSol = coordSol.keys()
		resNumsSol.sort()
		resNumsCl = coordCl.keys()
		resNumsCl.sort()
		chargeDict = self.parseCharges()
		diel = self.diel
		if len(self.resNums) > 0:
			resCalculate = self.resNums
		else:
			resCalculate = resNumsMol
		for resNumMol in resCalculate:
			if resNumMol == 1: continue 
			if 'H' not in coordMol[resNumMol].keys(): continue 
			linesN = []
			linesH = []
			fileNameN = 'energyN%s.txt'%resNumMol
			fileNameH = 'energyH%s.txt'%resNumMol
			if (os.path.isfile(fileNameN)) and (os.path.isfile(fileNameH)): continue
			print >> fd_progress, "\nPredicting ghost titrations for residue %d ...\n"%(resNumMol)
			fdN = open(fileNameN, 'a')
			fdH = open(fileNameH, 'a')
			ENside = 0
			ENback = 0
			ENsol = 0
			ENcl = 0
			ENtotal =0
			EHside = 0
			EHback = 0
			EHsol = 0
			EHcl = 0
			EHtotal =0
			counter = 1
			structNum = self.start
			while structNum <= self.end:
				fileName = self.pdb + '.pdb.' + str(structNum)
				filePath = os.path.join(os.getcwd(), fileName)
				if not (os.path.isfile(fileName) or os.path.isfile(filePath)):
					print "WARNING: PDB file %s does not exist "%fileName
					structNum += self.step
					continue
				coordMol, coordSol, coordCl = self.parseCoord(fileName)
				print >> fd_progress, "\tParsing coordinates from structure %s..."%(fileName)
				for resNum in resNumsMol:
					for atomName in coordMol[resNum].keys():
						if (atomName in backboneAtoms) and (abs(resNum-resNumMol)<2): continue
						try:
							coordN = coordMol[resNumMol]['N']
							coordC = coordMol[resNumMol-1]['C']
							coordH = coordMol[resNumMol]['H']
							distN, cosAngleN = getDistanceAngle(coordN,
								coordC, coordMol[resNum][atomName])
						except:
							continue
						try:
							distH, cosAngleH = getDistanceAngle(coordH,
								coordN, coordMol[resNum][atomName])
						except:
							continue
						charge = chargeDict[resNum][atomName]
						EN = fieldCoulomb(distN, cosAngleN, charge) * nsp['N'] / diel
						EH = fieldCoulomb(distH, cosAngleH, charge) * nsp['H'] / diel
						if atomName in backboneAtoms:
							ENback+=EN
							EHback+=EH
						else:
							ENside+=EN
							EHside+=EH
						ENtotal+=EN
						EHtotal+=EH
				for resNum in resNumsSol:
					for atomName in coordSol[resNum].keys():
						try:
							distN, cosAngleN = getDistanceAngle(coordN,
								coordC, coordSol[resNum][atomName])
						except:
							continue
						try:
							distH, cosAngleH = getDistanceAngle(coordH,
								coordN, coordSol[resNum][atomName])
						except:
							continue
						charge = chargesSol[atomName]
						EN = fieldCoulomb(distN, cosAngleN, charge) * nsp['N'] / diel
						EH = fieldCoulomb(distH, cosAngleH, charge) * nsp['H'] / diel
						ENsol+=EN
						EHsol+=EH
						ENtotal+=EN
						EHtotal+=EH
				for resNum in resNumsCl:
					try:
						distN, cosAngleN = getDistanceAngle(coordN,
							coordC, coordCl[resNum])
					except:
						continue
					try:
						distH, cosAngleH = getDistanceAngle(coordH,
							coordN, coordCl[resNum])
					except:
						continue
					charge = chargesSol['Cl-']
					ENcl+=fieldCoulomb(distN, cosAngleN, charge) * nsp['N'] / diel
					EHcl+=fieldCoulomb(distH, cosAngleH, charge) * nsp['H'] / diel
				lineN = '%5d  %10.6f  %10.6f  %10.6f  %10.6f  %10.6f\n'%(structNum, ENside/counter, ENback/counter, ENsol/counter, ENcl/counter, ENtotal/counter)
				fdN.write(lineN)
				lineH = '%5d  %10.6f  %10.6f  %10.6f  %10.6f  %10.6f\n'%(structNum, EHside/counter, EHback/counter, EHsol/counter, EHcl/counter, EHtotal/counter)
				fdH.write(lineH)
				structNum += self.step
				counter+=1
			fdN.close()
			fdH.close()
			print >> fd_progress, "\nDone...."
		fd_progress.close()
		return
def calculateCSP ( self ) : fd_progress = open ( "progress.log" , 'a' ) ; fileFirst = self . pdb + '.pdb.' + str ( self . start ) coordMol , coordSol , coordCl = self . parseCoord ( fileFirst ) resNumsMol = coordMol . keys ( ) resNumsMol . sort ( ) resNumsSol = coordSol . keys ( ) resNumsSol . sort ( ) resNumsCl = coordCl . keys ( ) resNumsCl . sort ( ) chargeDict = self . parseCharges ( ) diel = self . diel if len ( self . resNums ) > 0 : resCalculate = self . resNums else : resCalculate = resNumsMol for resNumMol in resCalculate : if resNumMol == 1 : continue if 'H' not in coordMol [ resNumMol ] . keys ( ) : continue linesN = [ ] linesH = [ ] fileNameN = 'energyN%s.txt' % resNumMol fileNameH = 'energyH%s.txt' % resNumMol if ( os . path . isfile ( fileNameN ) ) and ( os . path . isfile ( fileNameH ) ) : continue print >> fd_progress , "\nPredicting ghost titrations for residue %d ...\n" % ( resNumMol ) fdN = open ( fileNameN , 'a' ) fdH = open ( fileNameH , 'a' ) ENside = 0 ENback = 0 ENsol = 0 ENcl = 0 ENtotal = 0 EHside = 0 EHback = 0 EHsol = 0 EHcl = 0 EHtotal = 0 counter = 1 structNum = self . start while structNum <= self . end : fileName = self . pdb + '.pdb.' + str ( structNum ) filePath = os . path . join ( os . getcwd ( ) , fileName ) if not ( os . path . isfile ( fileName ) or os . path . isfile ( filePath ) ) : print "WARNING: PDB file %s does not exist " % fileName structNum += self . step continue coordMol , coordSol , coordCl = self . parseCoord ( fileName ) print >> fd_progress , "\tParsing coordinates from structure %s..." % ( fileName ) for resNum in resNumsMol : for atomName in coordMol [ resNum ] . keys ( ) : if ( atomName in backboneAtoms ) and ( abs ( resNum - resNumMol ) < 2 ) : continue try : coordN = coordMol [ resNumMol ] [ 'N' ] coordC = coordMol [ resNumMol - 1 ] [ 'C' ] coordH = coordMol [ resNumMol ] [ 'H' ] distN , cosAngleN = getDistanceAngle ( coordN , coordC , coordMol [ resNum ] [ atomName ] ) except : continue try : distH , cosAngleH = getDistanceAngle ( coordH , coordN , coordMol [ resNum ] [ atomName ] ) except : continue charge = chargeDict [ resNum ] [ atomName ] EN = fieldCoulomb ( distN , cosAngleN , charge ) * nsp [ 'N' ] / diel EH = fieldCoulomb ( distH , cosAngleH , charge ) * nsp [ 'H' ] / diel if atomName in backboneAtoms : ENback += EN EHback += EH else : ENside += EN EHside += EH ENtotal += EN EHtotal += EH for resNum in resNumsSol : for atomName in coordSol [ resNum ] . keys ( ) : try : distN , cosAngleN = getDistanceAngle ( coordN , coordC , coordSol [ resNum ] [ atomName ] ) except : continue try : distH , cosAngleH = getDistanceAngle ( coordH , coordN , coordSol [ resNum ] [ atomName ] ) except : continue charge = chargesSol [ atomName ] EN = fieldCoulomb ( distN , cosAngleN , charge ) * nsp [ 'N' ] / diel EH = fieldCoulomb ( distH , cosAngleH , charge ) * nsp [ 'H' ] / diel ENsol += EN EHsol += EH ENtotal += EN EHtotal += EH for resNum in resNumsCl : try : distN , cosAngleN = getDistanceAngle ( coordN , coordC , coordCl [ resNum ] ) except : continue try : distH , cosAngleH = getDistanceAngle ( coordH , coordN , coordCl [ resNum ] ) except : continue charge = chargesSol [ 'Cl-' ] ENcl += fieldCoulomb ( distN , cosAngleN , charge ) * nsp [ 'N' ] / diel EHcl += fieldCoulomb ( distH , cosAngleH , charge ) * nsp [ 'H' ] / diel lineN = '%5d  %10.6f  %10.6f  %10.6f  %10.6f  %10.6f\n' % ( structNum , ENside / counter , ENback / counter , ENsol / counter , ENcl / counter , ENtotal / counter ) fdN . write ( lineN ) lineH = '%5d  %10.6f  %10.6f  %10.6f  %10.6f  %10.6f\n' % ( structNum , EHside / counter , EHback / counter , EHsol / counter , EHcl / counter , EHtotal / counter ) fdH . write ( lineH ) structNum += self . step counter += 1 fdN . close ( ) fdH . close ( ) print >> fd_progress , "\nDone...." fd_progress . close ( ) return
calculates potentials of all N, C (N and H) atoms from num1 and num2 side chains, protein, water and Cl
calculates potentials of all N C ( N and H ) atoms from num1 and num2 side chains protein water and Cl
'''
		calculates potentials of all N, C (N and H) atoms from num1 and num2 side chains, protein, water and Cl
		''' #PROLINE #N #does not include Cl #H #does not include Cl #too close to backbone atom #print resNum, atomName #if not atomName in chargeDict[resNum].keys(): #	print 'Atom %s doesnt exist in topology file'%atomName #	continue #GLU charged doesn't have NE2 in top file
self