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
print('--- Get Forces ---') Fx, Fy, Fz = getForces( V, rho, sampleSize, dims, dd, X, Y, Z) print('Fx.max(), Fx.min() = ', Fx.max(), Fx.min()) PP.params['gridA'] = lvec[ 1,: ].copy() PP.params['gridB'] = lvec[ 2,: ].copy() PP.params['gridC'] = lvec[ 3,: ].copy() PP.params['gridN'] = nDim.copy() print("--- Compute Lennard-Jones Force-filed ---") atoms = basUtils.loadAtoms('input.xyz') if os.path.isfile( 'atomtypes.ini' ): print(">> LOADING LOCAL atomtypes.ini") FFparams=PPU.loadSpecies( 'atomtypes.ini' ) else: FFparams = PPU.loadSpecies( cpp_utils.PACKAGE_PATH+'/defaults/atomtypes.ini' ) iZs,Rs,Qs = PP.parseAtoms(atoms, autogeom = False, PBC = True, FFparams=FFparams) FFLJ = PP.computeLJ( Rs, iZs, FFLJ=None, FFparams=FFparams) print("--- Saving ---") GU.saveXSF('FFel_x.xsf', Fx, lvec, head) GU.saveXSF('FFel_y.xsf' , Fy, lvec, head) GU.saveXSF('FFel_z.xsf' , Fz, lvec, head) GU.saveVecFieldXsf( 'FFLJ', FFLJ, lvec, head)
X, Y, Z = getMGrid(dims, dd) print '--- Get Probe Density ---' rho = getProbeDensity(sampleSize, X, Y, Z, sigma, dd, {'dz2':1.0}) print '--- Get Forces ---' Fx, Fy, Fz = getForces( V, rho, sampleSize, dims, dd, X, Y, Z) print 'Fx.max(), Fx.min() = ', Fx.max(), Fx.min() PP.params['gridA'] = lvec[ 1,: ].copy() PP.params['gridB'] = lvec[ 2,: ].copy() PP.params['gridC'] = lvec[ 3,: ].copy() PP.params['gridN'] = nDim.copy() print "--- Compute Lennard-Jones Force-filed ---" atoms = basUtils.loadAtoms('input.xyz', elements.ELEMENT_DICT ) iZs,Rs,Qs = PP.parseAtoms( atoms, autogeom = False, PBC = True ) FFLJ = PP.computeLJ( Rs, iZs, FFLJ=None, FFparams=None) print "--- Saving ---" GU.saveXSF('FFel_x.xsf', Fx, lvec, head) GU.saveXSF('FFel_y.xsf' , Fy, lvec, head) GU.saveXSF('FFel_z.xsf' , Fz, lvec, head) GU.saveVecFieldXsf( 'FFLJ', FFLJ, lvec, head)
if query_yes_no( "I have found files containing electrostatic forcefield. Should I use them (yes) or do you want me to recompute them from scratch (n) ?" ): todoEL = 'read' else: todoEL = 'compute' else: print "I haven't found files containing electrostatic forcefields. Therefore I will recompute them from scratch" todoEL = 'compute' #print iZs if todoLJ == 'compute': FFLJ = PP.computeLJ(Rs, iZs, FFLJ=None, FFparams=None) GU.saveVecFieldXsf(ProjName + "_LJ_F", FFLJ, lvec=[[0.0, 0.0, 0.0], PP.params['gridA'], PP.params['gridB'], PP.params['gridC']]) elif todoLJ == 'read': FFLJ, lvec, nDim, head = GU.loadVecFieldXsf(ProjName + "_LJ_F") PP.lvec2params(lvec) xTips, yTips, zTips, lvecScan = PP.prepareScanGrids() print xTips, yTips, zTips if todoEL == 'read': FFEL, lvec, nDim, head = GU.loadVecFieldXsf(ProjName + "_EL_F") Q = PP.params['charge'] K = 0.3 PP.setTip(kSpring=np.array((K, K, 0.0)) / -PP.eVA_Nm)
): todoEL = "read" else: todoEL = "compute" else: print "I haven't found files containing electrostatic forcefields. Therefore I will recompute them from scratch" todoEL = "compute" # print iZs if todoLJ == "compute": FFLJ = PP.computeLJ(Rs, iZs, FFLJ=None, FFparams=None) GU.saveVecFieldXsf( ProjName + "_LJ_F", FFLJ, lvec=[[0.0, 0.0, 0.0], PP.params["gridA"], PP.params["gridB"], PP.params["gridC"]] ) elif todoLJ == "read": FFLJ, lvec, nDim, head = GU.loadVecFieldXsf(ProjName + "_LJ_F") PP.lvec2params(lvec) xTips, yTips, zTips, lvecScan = PP.prepareScanGrids() print xTips, yTips, zTips if todoEL == "read": FFEL, lvec, nDim, head = GU.loadVecFieldXsf(ProjName + "_EL_F") Q = PP.params["charge"]
else: print "I haven't found files containing electrostatic forcefields. Therefore I will recompute them from scratch" todoEL='compute' #print iZs if todoLJ == 'compute': FFLJ = PP.computeLJ( Rs, iZs, FFLJ=None, FFparams=None) GU.saveVecFieldXsf(ProjName+"_LJ_F",FFLJ, lvec=[[0.0,0.0,0.0],PP.params['gridA'], PP.params['gridB'],PP.params['gridC']] ) elif todoLJ == 'read': FFLJ, lvec, nDim, head = GU.loadVecFieldXsf( ProjName+"_LJ_F" ) PP.lvec2params( lvec ) xTips,yTips,zTips,lvecScan = PP.prepareScanGrids( ) print xTips,yTips,zTips if todoEL == 'read': FFEL, lvec, nDim, head = GU.loadVecFieldXsf( ProjName+"_EL_F" ) Q=PP.params['charge'] K=0.3