本文整理汇总了Python中ase.optimize.QuasiNewton.run方法的典型用法代码示例。如果您正苦于以下问题:Python QuasiNewton.run方法的具体用法?Python QuasiNewton.run怎么用?Python QuasiNewton.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ase.optimize.QuasiNewton
的用法示例。
在下文中一共展示了QuasiNewton.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_atoms
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
def get_atoms():
# 2x2-Al(001) surface with 3 layers and an
# Au atom adsorbed in a hollow site:
slab = fcc100('Al', size=(2, 2, 3))
add_adsorbate(slab, 'Au', 1.7, 'hollow')
slab.center(axis=2, vacuum=4.0)
# Fix second and third layers:
mask = [atom.tag > 1 for atom in slab]
slab.set_constraint(FixAtoms(mask=mask))
# Use EMT potential:
slab.set_calculator(EMT())
# Initial state:
qn = QuasiNewton(slab, logfile=None)
qn.run(fmax=0.05)
initial = slab.copy()
# Final state:
slab[-1].x += slab.get_cell()[0, 0] / 2
qn = QuasiNewton(slab, logfile=None)
qn.run(fmax=0.05)
final = slab.copy()
# Setup a NEB calculation
constraint = FixAtoms(mask=[atom.tag > 1 for atom in initial])
images = [initial]
for i in range(3):
image = initial.copy()
image.set_constraint(constraint)
images.append(image)
images.append(final)
neb = NEB(images, parallel=mpi.parallel)
neb.interpolate()
def set_calculator(calc):
i = 0
for image in neb.images[1:-1]:
if not mpi.parallel or mpi.rank // (mpi.size // 3) == i:
image.set_calculator(calc)
i += 1
neb.set_calculator = set_calculator
return neb
示例2: aual100
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
def aual100(site, height, calc=None):
slab = fcc100('Al', size=(2, 2, 1))
add_adsorbate(slab, 'Au', height, site)
slab.center(axis=2, vacuum=3.0)
mask = [atom.symbol == 'Al' for atom in slab]
fixlayer = FixAtoms(mask=mask)
slab.set_constraint(fixlayer)
if calc is None:
calc = GPAW(h=0.25, kpts=(2, 2, 1), xc='PBE', txt=site + '.txt')
slab.set_calculator(calc)
qn = QuasiNewton(slab, trajectory=site + '.traj')
qn.run(fmax=0.05)
if isinstance(calc, GPAW):
calc.write(site + '.gpw')
return slab.get_potential_energy()
示例3: evaluate
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
def evaluate(self, imember):
entry = self.population.get_entry(imember)
pcm_structure = pychemia.Structure.from_dict(entry['structure'])
ase_structure = pychemia.external.ase.pychemia2ase(pcm_structure)
ase_structure.set_calculator(LennardJones())
dyn = QuasiNewton(ase_structure)
dyn.run()
ase_structure.set_constraint(FixAtoms(mask=[True for atom in ase_structure]))
ucf = UnitCellFilter(ase_structure)
qn = QuasiNewton(ucf)
qn.run()
new_structure = pychemia.external.ase.ase2pychemia(ase_structure)
energy = ase_structure.get_potential_energy()
forces = ase_structure.get_forces()
stress = ase_structure.get_stress()
new_properties = {'energy': float(energy), 'forces': generic_serializer(forces),
'stress': generic_serializer(stress)}
self.population.db.update(imember, structure=new_structure, properties=new_properties)
示例4: Specie
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
cell=[10, 10, 10])
c_basis = """2 nodes 1.00
0 1 S 0.20 P 1 0.20 6.00
5.00
1.00
1 2 S 0.20 P 1 E 0.20 6.00
6.00 5.00
1.00 0.95"""
specie = Specie(symbol='C', basis_set=PAOBasisBlock(c_basis))
calc = Siesta(
label='ch4',
basis_set='SZ',
xc='LYP',
mesh_cutoff=300 * Ry,
species=[specie],
restart='ch4.XV',
ignore_bad_restart_file=True,
fdf_arguments={'DM.Tolerance': 1E-5,
'DM.MixingWeight': 0.15,
'DM.NumberPulay': 3,
'MaxSCFIterations': 200,
'ElectronicTemperature': 0.02585 * eV, # 300 K
'SaveElectrostaticPotential': True})
bud.set_calculator(calc)
dyn = QuasiNewton(bud, trajectory=traj)
dyn.run(fmax=0.02)
e = bud.get_potential_energy()
示例5: Atoms
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
from ase import Atoms
from ase.visualize import view
from ase.calculators.aims import Aims, AimsCube
from ase.optimize import QuasiNewton
water = Atoms('HOH', [(1,0,0), (0,0,0), (0,1,0)])
water_cube = AimsCube(points=(29,29,29),
plots=('total_density','delta_density',
'eigenstate 5','eigenstate 6'))
calc=Aims(xc='pbe',
sc_accuracy_etot=1e-6,
sc_accuracy_eev=1e-3,
sc_accuracy_rho=1e-6,
sc_accuracy_forces=1e-4,
species_dir='/home/hanke/codes/fhi-aims/fhi-aims.workshop/species_defaults/light/',
run_command='aims.workshop.serial.x',
cubes=water_cube)
water.set_calculator(calc)
dynamics = QuasiNewton(water,trajectory='square_water.traj')
dynamics.run(fmax=0.01)
view(water)
示例6: espresso
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
atoms.center(vacuum = 10.0)
atoms.set_cell([[10,0,0],[0,10.1,0],[0,0,10.2]])
calc = espresso(pw = 500.,
dw = 5000.,
nbands = -10,
kpts=(1, 1, 1),
xc = 'BEEF',
outdir='outdir',
psppath = "/scratch/users/colinfd/psp/gbrv",
sigma = 10e-4)
atoms.set_calculator(calc)
dyn = QuasiNewton(atoms,logfile='out.log',trajectory='out.traj')
dyn.run(fmax=0.01)
electronicenergy = atoms.get_potential_energy()
vib = Vibrations(atoms) # run vibrations on all atoms
vib.run()
vib_energies = vib.get_energies()
thermo = IdealGasThermo(vib_energies=vib_energies,
electronicenergy=electronicenergy,
atoms=atoms,
geometry='linear', # linear/nonlinear
symmetrynumber=2, spin=0) # symmetry numbers from point group
G = thermo.get_free_energy(temperature=300, pressure=101325.) # vapor pressure of water at room temperature
e = open('e_energy.out','w')
示例7: molecule
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
#!/usr/bin/env python
#
import os
from ase import Atoms
from ase.calculators.dftb import Dftb
from ase.optimize import QuasiNewton
from ase.io import write, read
from ase.structure import molecule
test = molecule('H2O')
test.set_calculator(Dftb(label='h2o',atoms=test,
run_manyDftb_steps = True,
Driver_='ConjugateGradient',
Driver_MaxForceComponent='1E-4',
Driver_MaxSteps=1000,
Hamiltonian_MaxAngularMomentum_ = '',
Hamiltonian_MaxAngularMomentum_O = '"p"',
Hamiltonian_MaxAngularMomentum_H = '"s"',
))
dyn = QuasiNewton(test, trajectory='test.traj')
dyn.run(fmax=100, steps=0)
test = read('geo_end.gen')
write('test.final.xyz', test)
示例8: fcc100
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
# Initial state:
# 2x2-Al(001) surface with 1 layer and an
# Au atom adsorbed in a hollow site:
slab = fcc100('Al', size=(2, 2, 2))
slab.center(axis=2, vacuum=3.0)
add_adsorbate(slab, 'Au', 1.6, 'hollow')
# Make sure the structure is correct:
view(slab)
# Fix the Al atoms:
mask = [atom.symbol == 'Al' for atom in slab]
print(mask)
fixlayer = FixAtoms(mask=mask)
slab.set_constraint(fixlayer)
# Use GPAW:
calc = GPAW(mode=PW(200), kpts=(2, 2, 1), xc='PBE', txt='hollow.txt')
slab.set_calculator(calc)
qn = QuasiNewton(slab, trajectory='hollow.traj')
# Find optimal height. The stopping criterion is: the force on the
# Au atom should be less than 0.05 eV/Ang
qn.run(fmax=0.05)
calc.write('hollow.gpw') # Write gpw output after the minimization
print('energy:', slab.get_potential_energy())
print('height:', slab.positions[-1, 2] - slab.positions[0, 2])
示例9: FixAtoms
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
i = 0
array = []
while i < 6:
if atoms.positions[i][0] <= -2.0:
array.append(i)
i += 1
else:
i += 1
c = FixAtoms(indices = array)
atoms.set_constraint(c)
# relax with Quasi Newtonian
qn = QuasiNewton(atoms, trajectory='qn.traj')
qn.run(fmax=0.001)
write('qn.final.xyz', atoms)
# Set the momenta corresponding to T=300K
MaxwellBoltzmannDistribution(atoms, 300*units.kB)
print 'Removing linear momentum and angular momentum'
Stationary(atoms) # zero linear momentum
ZeroRotation(atoms) # zero angular momentum
# We want to run MD using the VelocityVerlet algorithm.
dyn = VelocityVerlet(atoms, 0.1*units.fs, trajectory='moldyn4.traj') # save trajectory.
#Function to print the potential, kinetic and total energy.
def printenergy(a=atoms): #store a reference to atoms in the definition.
epot = a.get_potential_energy() / len(a)
ekin = a.get_kinetic_energy() / len(a)
示例10: FixAtoms
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
constraint = FixAtoms(indices=[1, 3]) # fix OO #BUG No.1: fixes atom 0 and 1
#constraint = FixAtoms(mask=[0,1,0,1,0]) # fix OO #Works without patch
for image in images:
image.set_calculator(Turbomole()) #BUG No.2: (Over-)writes coord file
image.set_constraint(constraint)
# Write all commands for the define command in a string
define_str = '\n\na coord\n\n*\nno\nb all 3-21g hondo\n*\neht\n\n-1\nno\ns\n*\n\ndft\non\nfunc pwlda\n\n\nscf\niter\n300\n\n*'
# Run define
p = Popen('define', stdout=PIPE, stdin=PIPE, stderr=STDOUT)
stdout = p.communicate(input=define_str)
# Relax initial and final states:
if 1:
dyn1 = QuasiNewton(images[0])
dyn1.run(fmax=0.10)
dyn2 = QuasiNewton(images[-1])
dyn2.run(fmax=0.10)
# Interpolate positions between initial and final states:
neb.interpolate()
if 1:
for image in images:
print image.get_distance(1, 2), image.get_potential_energy()
dyn = BFGS(neb, trajectory='turbomole_h3o2m.traj')
dyn.run(fmax=0.10)
for image in images:
print image.get_distance(1, 2), image.get_potential_energy()
示例11: Siesta
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
e_shifts = [0.01,0.1,0.2,0.3,0.4,0.5]
# Run the relaxation for each energy shift, and print out the
# corresponding total energy, bond length and angle
for e_s in e_shifts:
starttime = time.time()
calc = Siesta('h2o',meshcutoff=200.0 * units.Ry, mix=0.5, pulay=4)
calc.set_fdf('PAO.EnergyShift', e_s * units.eV)
calc.set_fdf('PAO.SplitNorm', 0.15)
calc.set_fdf('PAO.BasisSize', 'SZ')
h2o.set_calculator(calc)
# Make a -traj file named h2o_current_shift.traj:
dyn = QuasiNewton(h2o, trajectory='h2o_%s.traj' % e_s)
dyn.run(fmax=0.02) # Perform the relaxation
E = h2o.get_potential_energy()
print # Make the output more readable
print "E_shift: %.2f" %e_s
print "----------------"
print "Total Energy: %.4f" % E # Print total energy
d = h2o.get_distance(0,2)
print "Bond length: %.4f" % d # Print bond length
p = h2o.positions
d1 = p[0] - p[2]
d2 = p[1] - p[2]
r = np.dot(d1, d2) / (np.linalg.norm(d1) * np.linalg.norm(d2))
angle = np.arccos(r) / pi * 180
print "Bond angle: %.4f" % angle # Print bond angle
endtime = time.time()
walltime = endtime - starttime
示例12: molecule
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
from ase.data.molecules import molecule
from ase.optimize import QuasiNewton
from gpaw import GPAW
for name in ['H2', 'N2', 'O2', 'NO']:
mol = molecule(name)
mol.center(vacuum=5.0)
if name == 'NO':
mol.translate((0, 0.1, 0))
calc = GPAW(xc='PBE',
h=0.2,
stencils=(3, 3),
txt=name + '.txt')
mol.set_calculator(calc)
opt = QuasiNewton(mol, logfile=name + '.log', trajectory=name + '.traj')
opt.run(fmax=0.05)
calc.write(name)
示例13: Hookean_Always
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
Hamiltonian_MaxAngularMomentum_='',
Hamiltonian_MaxAngularMomentum_H='"s"',
))
c = Hookean_Always(a1=0, a2=1, k=0, rt=0.6)
atoms.set_constraint(c)
OP = []
def print_distance(a=atoms):
distance = a.get_distance(a0=0,a1=1)
OP.append(distance)
epot = a.get_potential_energy() / len(a)
ekin = a.get_kinetic_energy() / len(a)
ETOT = epot+ekin
OP.append(ETOT)
dyn = QuasiNewton(atoms, trajectory='atoms.traj')
dyn.attach(print_distance)
dyn.run(steps=10)
print atoms.get_distance(a0=0, a1=1)
write('test.final.xyz', atoms)
OP_f = [OP[i:i+2] for i in xrange(0,len(OP),2)]
OP_f_text = np.savetxt('out.tmp', OP_f) # reads array and saves into a file as a string
OP_f_infile = open('out.tmp','r') # open file to write string array onto
OP_f_text = OP_f_infile.read()
text_file.write(OP_f_text)
text_file.close()
示例14: EMT
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
# see the module for the required format of reactions definition
from ase.test.cmr.reactions import reactions
# assure that all reactions define a reaction_id
for r in reactions:
assert r[-1][0] == 'reaction_id'
optimize = True
calculator = EMT()
# find names of compounds
# (in one of the most obscure ways - python list flattening)
compounds = [c[0] for c in sum([r[:-1] for r in reactions], [])]
# unique
compounds = list(set(compounds))
for formula in compounds:
m = molecule(formula)
m.set_calculator(calculator)
if optimize:
dyn = QuasiNewton(m,
logfile=('%s.log' % formula),
trajectory=('%s.traj' % formula),
)
dyn.run()
else:
e = m.get_potential_energy()
write(filename=('%s.traj' % formula), images=m, format='traj')
示例15: FaceCenteredCubic
# 需要导入模块: from ase.optimize import QuasiNewton [as 别名]
# 或者: from ase.optimize.QuasiNewton import run [as 别名]
else:
from ase.calculators.emt import EMT
size = 2
# Set up a nanoparticle
atoms = FaceCenteredCubic('Cu',
surfaces=[[1, 0, 0], [1, 1, 0], [1, 1, 1]],
layers=(size, size, size),
vacuum=4)
# Describe the interatomic interactions with the Effective Medium Theory
atoms.set_calculator(EMT())
# Do a quick relaxation of the cluster
qn = QuasiNewton(atoms)
qn.run(0.001, 10)
# Set the momenta corresponding to T=1200K
MaxwellBoltzmannDistribution(atoms, 1200 * units.kB)
Stationary(atoms) # zero linear momentum
ZeroRotation(atoms) # zero angular momentum
# We want to run MD using the VelocityVerlet algorithm.
# Save trajectory:
dyn = VelocityVerlet(atoms, 5 * units.fs, trajectory='moldyn4.traj')
def printenergy(a=atoms): # store a reference to atoms in the definition.
"""Function to print the potential, kinetic and total energy."""
epot = a.get_potential_energy() / len(a)