Esempio n. 1
0
def prepareForceFields( store = True, storeXsf = False, autogeom = False, FFparams=None ):
	newEl = False
	newLJ = False
	head = None
	# --- try to load FFel or compute it from LOCPOT.xsf
	if ( os.path.isfile('FFel_x.xsf') ):
		print " FFel_x.xsf found "
		FFel, lvecEl, nDim, head = GU.loadVecField('FFel', FFel)
		lvec2params( lvecEl )
	else:
		print "FFel_x.xsf not found "
		if ( xsfLJ  and os.path.isfile('LOCPOT.xsf') ):
			print " LOCPOT.xsf found "
			V, lvecEl, nDim, head = GU.loadXSF('LOCPOT.xsf')
			lvec2params( lvecEl )
			FFel_x,FFel_y,FFel_z = libFFTfin.potential2forces( V, lvecEl, nDim, sigma = 1.0 )
			FFel = GU.packVecGrid( FFel_x,FFel_y,FFel_z )
			del FFel_x,FFel_y,FFel_z
			GU.saveVecFieldXsf( 'FFel', FF, lvecEl, head = head )
		else:
			print " LOCPOT.xsf not found "
			newEl = True
	# --- try to load FFLJ 
	if ( os.path.isfile('FFLJ_x.xsf') ):
		print " FFLJ_x.xsf found "
		FFLJ, lvecLJ, nDim, head = GU.loadVecFieldXsf( 'FFLJ' )
		lvec2params( lvecLJ )
	else: 
		newLJ = True
	# --- compute Forcefield by atom-wise interactions 
	if ( newEl or newEl ):
		atoms     = basUtils.loadAtoms('geom.bas', elements.ELEMENT_DICT )
		iZs,Rs,Qs = parseAtoms( atoms, autogeom = autogeom, PBC = params['PBC'] )
		lvec = params2lvec( )
		if head is None:
			head = GU.XSF_HEAD_DEFAULT
		if newLJ:
			FFLJ = computeLJ     ( Rs, iZs, FFparams=FFparams )
			GU.saveVecFieldXsf( 'FFLJ', FF, lvecEl, head = head )
		if newEl:
			FFel = computeCoulomb( Rs, Qs, FFel )
			GU.saveVecFieldXsf( 'FFel', FF, lvecEl, head = head )
	return FFLJ, FFel
sigma = 1.0  # [ Angstroem ]

print " >> OVEWRITING SETTINGS by params.ini  "
PPU.loadParams('params.ini')

print " ========= get electrostatic forcefiled from hartree "

# TODO with time implement reading a hartree potential generated by different software
print " loading Hartree potential from disk "
if (options.input == 'vasp.locpot.xsf'):
    V, lvec, nDim, head = GU.loadXSF(finput)
elif (options.input == 'aims.cube'):
    V, lvec, nDim, head = GU.loadCUBE(finput)

print " computing convolution with tip by FFT "
Fel_x, Fel_y, Fel_z = LFF.potential2forces(V, lvec, nDim, sigma=1.0)

print " saving electrostatic forcefiled "
GU.saveXSF('FFel_x.xsf', Fel_x, lvec, head)
GU.saveXSF('FFel_y.xsf', Fel_y, lvec, head)
GU.saveXSF('FFel_z.xsf', Fel_z, lvec, head)

del Fel_x, Fel_y, Fel_z, V

print " ========= get lenard jones potential "

PPU.params['gridA'] = lvec[1, :].copy()
PPU.params['gridB'] = lvec[2, :].copy()
PPU.params['gridC'] = lvec[3, :].copy()
PPU.params['gridN'] = nDim.copy()