示例#1
0
def minimize_energy(traj_file):
	"""
	Run a BFGS energy minimization of the smamp molecule in vacuum.

	Args:
	traj_file: the path to a trajectory file (all atom format)

	Returns:
	struc: an internal molecular structure object
	calc: internal calculation object	
	"""

	# Read in the trajectory file
	struc = read(traj_file)
	# Set up the box
	struc.set_cell([25,25,25])
	struc.set_pbc([0,0,0])
	struc.center()
	# Define gpaw convergence&simulation parameters
	calc  = GPAW(xc='PBE', h=0.2, charge=0,
		     spinpol=True, convergence={'energy': 0.001})
	struc.set_calculator(calc)
	dyn = BFGSLineSearch(struc, trajectory='molecule.traj',
			     restart='bfgs_ls.pckl', logfile='BFGSLinSearch.log')

	# run the simulation
	dyn.run(fmax=0.05)

	# Maybe this is useful? Does not seem to be needed.
	# Epot  = struc.get_potential_energy()

	# Save everything into a restart file
	calc.write('restart.gpw', mode='all')

	return struc, calc
示例#2
0
 def minimise (self,cluster):
     '''Minimise a cluster
     parameters:
     cluster- a Cluster object from bcga.cluster
     
     Using this method will overwrite the coordinates and energy of the
     supplied Cluster object.'''
     # Fix overlapping atoms to avoid NWChem errors
     cluster.fix_overlaps(1.5)
     # Set up element labels for NWChem
     atom_string=""
     for i in range(0,len(cluster.labels)):
         atom_string+=cluster.labels[i]+str(get_composition(cluster.atom_types)[i])
     print(atom_string)
     mol = Atoms(atom_string,
                   positions=cluster._coords,
                   cell=(6.0,6.0,6.0))
     mol.center()
     # Run GPAW calculation
     calc = GPAW(**self.GPAWargs)
     mol.set_calculator(calc)
     opt = BFGSLineSearch(mol)
     try:
         opt.run(fmax=0.25)
     except:
         sys.exit()
     # Get back cluster properties from GPAW
     cluster.energy=mol.get_potential_energy()
     cluster.quenched=True
     return cluster
 def minimise(self, cluster):
     '''Minimise a cluster
     parameters:
     cluster- a Cluster object from bcga.cluster
     
     Using this method will overwrite the coordinates and energy of the
     supplied Cluster object.'''
     # Fix overlapping atoms to avoid NWChem errors
     cluster.fix_overlaps(1.5)
     # Set up element labels for NWChem
     atom_string = ""
     for i in range(0, len(cluster.labels)):
         atom_string += cluster.labels[i] + str(
             get_composition(cluster.atom_types)[i])
     print(atom_string)
     mol = Atoms(atom_string,
                 positions=cluster._coords,
                 cell=(6.0, 6.0, 6.0))
     mol.center()
     # Run GPAW calculation
     calc = GPAW(**self.GPAWargs)
     mol.set_calculator(calc)
     opt = BFGSLineSearch(mol)
     try:
         opt.run(fmax=0.25)
     except:
         sys.exit()
     # Get back cluster properties from GPAW
     cluster.energy = mol.get_potential_energy()
     cluster.quenched = True
     return cluster
示例#4
0
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 maxstep=.2,
                 trajectory=None,
                 c1=0.23,
                 c2=0.46,
                 alpha=10.0,
                 stpmax=50.0,
                 master=None,
                 force_consistent=None,
                 zlim=None):
        """
        add zlim to BFGSLineSearch:

        zlim = [z_min, z_max]
        """

        self.zlim = zlim

        BFGSLineSearch.__init__(self,
                                atoms,
                                restart=restart,
                                logfile=logfile,
                                maxstep=maxstep,
                                trajectory=trajectory,
                                c1=c1,
                                c2=c2,
                                alpha=alpha,
                                stpmax=stpmax,
                                master=master,
                                force_consistent=force_consistent)
示例#5
0
def createparticle(type1, type2, numbertype1):
    calc = QSC()
    atoms = ase.io.read('POSCAR_genetic', format='vasp')
    shell = deepcopy(atoms)
    core = deepcopy(atoms)
    for i in range(85, 225):
        core.pop(85)
    for i in range(85):
        shell.pop(0)
    dummyarray = core.get_chemical_symbols()
    for i in range(numbertype1):
        dummyarray[i] = type1
    for i in range(numbertype1, 85):
        dummyarray[i] = type2
    random.shuffle(dummyarray)
    core.set_chemical_symbols(dummyarray)
    for i in range(len(shell)):
        core.append(shell.pop(0))
    core.set_calculator(calc)
    opt = BFGSLineSearch(core)
    opt.run(steps=8)
    opt = FIRE(core)
    opt.run(steps=2000)
    return core
示例#6
0
def createparticle(type1, type2, numbertype1):
	calc = QSC()
	atoms = ase.io.read('POSCAR_genetic',format='vasp')	
	shell = deepcopy(atoms)
	core = deepcopy(atoms)
	for i in range(85,225):
		core.pop(85)
	for i in range(85):
		shell.pop(0)
	dummyarray = core.get_chemical_symbols()
	for i in range(numbertype1):
		dummyarray[i] = type1
	for i in range(numbertype1,85):
		dummyarray[i] = type2
	random.shuffle(dummyarray)
	core.set_chemical_symbols(dummyarray)
	for i in range(len(shell)):
		core.append(shell.pop(0))
	core.set_calculator(calc)
	opt = BFGSLineSearch(core)
	opt.run(steps=8)
	opt =  FIRE(core)
	opt.run(steps=2000)
	return core
示例#7
0
#!/usr/bin/env python

#PBS -m ae
#PBS -q verylong
#PBS -l nodes=1:ppn=8
#!/usr/bin/env python

from ase.io import read
from gpaw import GPAW
from ase.optimize.bfgslinesearch import BFGSLineSearch

slab = read('CH4Au532.xyz')
slab.set_cell([[7.309254, 0., 0.], [4.872836, 7.509545, 0.], [0., 0., 20.]],
              scale_atoms=False)
slab.set_pbc((1, 1, 1))

calc = GPAW(h=0.18, kpts=(4, 4, 1))
slab.set_calculator(calc)

dyn = BFGSLineSearch(slab, trajectory='relax.traj')
dyn.run(fmax=0.02)
示例#8
0
parser.add_argument('outfile_pckl',
                    nargs='?',
                    metavar='bfgs_ls.pckl',
                    default='bfgs_ls.pckl',
                    help="Restart file, default 'bfgs_ls.pckl'")
parser.add_argument('logfile',
                    nargs='?',
                    metavar='BFGSLinSearch.log',
                    default='BFGSLinSearch.log',
                    help="Optimization's log, default 'BFGSLinSearch.log'")

args = parser.parse_args()

struc = molecule('H2O')
struc.set_pbc([0, 0, 0])
struc.set_cell([5, 5, 5])
struc.center()

calc = GPAW(xc='PBE',
            h=0.2,
            charge=0,
            spinpol=True,
            convergence={'energy': 0.001})
struc.set_calculator(calc)

dyn = BFGSLineSearch(struc,
                     trajectory=args.outfile_traj,
                     restart=args.outfile_pckl,
                     logfile=args.logfile)
dyn.run(fmax=0.05)
示例#9
0
traj_file = 'benzene.traj'

if not os.path.isfile(traj_file):
    struc.set_cell([15, 15, 15])
    struc.set_pbc([0, 0, 0])
    struc.center()
    calc = GPAW(xc='PBE',
                h=0.2,
                charge=0,
                spinpol=True,
                convergence={'energy': 0.001})

    struc.set_calculator(calc)
    #opt   = FIRE(struc, trajectory='benzene.traj', logfile='fire.log')
    dyn = BFGSLineSearch(struc,
                         trajectory=traj_file,
                         restart='bfgs_ls.pckl',
                         logfile='BFGSLinSearch.log')
    dyn.run(fmax=0.05)

# Did not find any documentation on how to directly continue with results
struc = read(traj_file)
calc = GPAW(xc='PBE',
            h=0.2,
            charge=0,
            spinpol=True,
            convergence={'energy': 0.001})
struc.set_calculator(calc)  # is it necessary?
struc.get_potential_energy()

vHtg = struc.calc.get_electrostatic_potential()
rho4 = struc.calc.get_all_electron_density(gridrefinement=4)
cluster = read('Au55.xyz')
cell = [(17.79365715,0,0),
        (0,19.60846479,0),
        (0,0, 19.84025464)]
cluster.set_cell(cell,scale_atoms=False)
cluster.center()

kwargs_lcao = dict(mode='lcao',
              #basis='dzp',
              convergence={'density':0.1, 'energy':0.1}
              )#poissonsolver=poissonsolver)

calc = GPAW(h=0.18,txt=None,**kwargs_lcao)
cluster.set_calculator(calc)

dyn1 = BFGSLineSearch(cluster, trajectory='Au_cluster_lcao.traj')
dyn1.run(fmax=0.02)
e_cluster_lcao = cluster.get_potential_energy()

#cluster.set_calculator(GPAW(h=0.18,tex=None))
dyn2 = BFGSLineSearch(cluster, trajectory='Au_cluster_paw.traj')
dyn2.run(fmax=0.02)
e_cluster_paw = cluster.get_potential_energy()

#Relax CO molecule with both lcao and paw modes
CO = Atoms([Atom('C',(1.0,1.0,1.0)),
            Atom('O',(1.0,1.0,2.3))],
            cell=(12,12.5,14.5))
CO.set_calculator(calc)
CO.center()
dyn3 = BFGSLineSearch(CO)
示例#11
0
#Relax the Au 55 atoms cluster with both lcao and paw modes
cluster = read('Au55.xyz')
cell = [(17.79365715,0,0),
        (0,19.60846479,0),
        (0,0, 19.84025464)]
cluster.set_cell(cell,scale_atoms=False)
cluster.center()

kwargs_lcao = dict(mode='lcao',
              #basis='dzp',
              convergence={'density':0.1, 'energy':0.1})

calc = GPAW(h=0.18,txt=None,**kwargs_lcao)
cluster.set_calculator(calc)

dyn1 = BFGSLineSearch(cluster, trajectory='Au_cluster_lcao.traj')
dyn1.run(fmax=0.02)
e_cluster_lcao = cluster.get_potential_energy()

#cluster.set_calculator(GPAW(h=0.18,tex=None))
dyn2 = BFGSLineSearch(cluster, trajectory='Au_cluster_paw.traj')
dyn2.run(fmax=0.02)
e_cluster_paw = cluster.get_potential_energy()

#Relax CO molecule with both lcao and paw modes
CO = Atoms([Atom('C',(1.0,1.0,1.0)),
            Atom('O',(1.0,1.0,2.3))],
            cell=(12,12.5,14.5))
CO.set_calculator(calc)
CO.center()
dyn3 = BFGSLineSearch(CO)
示例#12
0
from ase.io import read
from gpaw import GPAW
from ase.optimize.bfgslinesearch import BFGSLineSearch

slab = read('CH4Au532.xyz')
slab.set_cell([[7.309254, 0., 0.], [4.872836, 7.509545, 0.], [0., 0., 20.]],scale_atoms=False)
slab.set_pbc((1,1,1))

calc = GPAW(h=0.18, kpts=(4, 4, 1))
slab.set_calculator(calc)

dyn = BFGSLineSearch(slab,trajectory='relax.traj')
dyn.run(fmax=0.02)
示例#13
0
r_OH2 = 1.90792059
theta = 114.4996469200000 * np.pi / 180.0

r_o, r_h1, r_h2 = get_cart_coords_h2o(r_OH1, r_OH2, theta, [0.0,0.0, 0.0])

atoms = Atoms('OHH', positions=[r_o, r_h1, r_h2])

calc  = H2o_pjt2_calculator()
atoms.set_calculator(calc)

E = atoms.get_potential_energy()

print(E)

# optimize geometry
dyn = BFGSLineSearch(atoms, logfile='h2o_opt.log')
dyn.run(fmax=0.00001)

pos = atoms.get_positions()

q1,q2,theta = get_internal_coords_h2o(pos[0], pos[1], pos[2])
coords = [q1, q2, theta * 180/np.pi]

ref=np.array([0.957920759532, 0.957920773357, 104.499646202])

error = np.sqrt(np.sum((coords - ref)**2))
print('coords')
print(coords)
print('diff from reference:')
print(error)