本文整理匯總了Python中ase.optimize.BFGS屬性的典型用法代碼示例。如果您正苦於以下問題:Python optimize.BFGS屬性的具體用法?Python optimize.BFGS怎麽用?Python optimize.BFGS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類ase.optimize
的用法示例。
在下文中一共展示了optimize.BFGS屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testRMSE
# 需要導入模塊: from ase import optimize [as 別名]
# 或者: from ase.optimize import BFGS [as 別名]
def testRMSE(self):
datafile = os.path.join(path, 'test_data/NeuroChemOptimized/all')
with open(datafile, 'rb') as f:
all_atoms = pickle.load(f)
for atoms in all_atoms:
# reconstructing Atoms object.
# ASE does not support loading pickled object from older version
atoms = Atoms(atoms.get_chemical_symbols(), positions=atoms.get_positions())
old_coordinates = copy.deepcopy(atoms.get_positions())
old_coordinates = torch.from_numpy(old_coordinates)
atoms.set_calculator(self.calculator)
opt = BFGS(atoms)
opt.run()
coordinates = atoms.get_positions()
coordinates = torch.from_numpy(coordinates)
distances = (old_coordinates - coordinates).norm(dim=1)
rmse = distances.mean()
self.assertLess(rmse, self.tolerance)
示例2: _relax_with_ase
# 需要導入模塊: from ase import optimize [as 別名]
# 或者: from ase.optimize import BFGS [as 別名]
def _relax_with_ase(atoms, vasp_flags):
'''
Instead of letting VASP handle the relaxation autonomously, we instead use
VASP only as an eletronic structure calculator and use ASE's BFGS to
perform the atomic position optimization.
Note that this will also write the trajectory to the 'all.traj' file and
save the log file as 'relax.log'.
Args:
atoms `ase.Atoms` object of the structure we want to relax
vasp_flags A dictionary of settings we want to pass to the `Vasp2`
calculator
Returns:
atoms The relaxed `ase.Atoms` structure
'''
vasp_flags['ibrion'] = 2
vasp_flags['nsw'] = 0
calc = Vasp2(**vasp_flags)
atoms.set_calculator(calc)
optimizer = BFGS(atoms, logfile='relax.log', trajectory='all.traj')
optimizer.run(fmax=vasp_flags['ediffg'] if 'ediffg' in vasp_flags else 0.05)
return atoms
示例3: relax_atoms
# 需要導入模塊: from ase import optimize [as 別名]
# 或者: from ase.optimize import BFGS [as 別名]
def relax_atoms(atoms):
'''
Performs a quick, rough relaxation of an atoms object using EMT and BFGS.
Arg:
atoms ase.Atoms object that you want to relax
Output:
atoms Relaxed version of the input
'''
calculator = EMT()
atoms.set_calculator(calculator)
dynamics = BFGS(atoms)
dynamics.run()
return atoms
示例4: test_lammps_calculator
# 需要導入模塊: from ase import optimize [as 別名]
# 或者: from ase.optimize import BFGS [as 別名]
def test_lammps_calculator():
if not have_ase():
skip("no ASE found, skipping test")
elif not have_lmp():
skip("no lammps found, skipping test")
else:
at = get_atoms_with_calc_lammps()
at.rattle(stdev=0.001, seed=int(time.time()))
common.makedirs(at.calc.directory)
print(common.backtick("cp -v utils/lammps/AlN.tersoff {p}/".format(
p=at.calc.directory)))
print("scf")
forces = at.get_forces()
etot = at.get_potential_energy()
stress = at.get_stress(voigt=False) # 3x3
st = io.read_lammps_md_txt(at.calc.label + '.out')[0]
assert np.allclose(forces, st.forces)
assert np.allclose(etot, st.etot)
assert np.allclose(st.stress, -stress * constants.eV_by_Ang3_to_GPa,
atol=1e-10)
print("relax")
from ase.optimize import BFGS
opt = BFGS(at, maxstep=0.04)
opt.run(fmax=0.001, steps=10)
coords_frac = parse.arr2d_from_txt("""
3.3333341909920072e-01 6.6666683819841532e-01 4.4325467247779138e-03
6.6666681184103216e-01 3.3333362368205072e-01 5.0443254824788963e-01
3.3333341909918301e-01 6.6666683819838046e-01 3.8356759709402671e-01
6.6666681184101539e-01 3.3333362368201563e-01 8.8356759861713752e-01
""")
assert np.allclose(coords_frac, at.get_scaled_positions(), atol=1e-2)
# at least 1 backup files must exist
assert os.path.exists(at.calc.infile + '.0')
assert os.path.exists(at.calc.outfile + '.0')
assert os.path.exists(at.calc.dumpfile + '.0')
assert os.path.exists(at.calc.structfile + '.0')
示例5: optimize_lammpslib
# 需要導入模塊: from ase import optimize [as 別名]
# 或者: from ase.optimize import BFGS [as 別名]
def optimize_lammpslib(pbcgb, lmp, parameters, path, method='FIRE', fmax=0.1):
lammps = LAMMPSlib(lmp=lmp, lmpcmds=parameters, log_file='lammps.log', path=path)
pbcgb.set_calculator(lammps)
cell0=pbcgb.cell
fixstrain = np.zeros((3,3))
fixstrain[2][2] = 1
box = mushybox(pbcgb, fixstrain=fixstrain)
if method == 'FIRE':
dyn = FIRE(box)
else:
dyn = BFGS(box)
dyn.run(fmax=fmax, steps=500)
return pbcgb
示例6: test_pwscf_calculator
# 需要導入模塊: from ase import optimize [as 別名]
# 或者: from ase.optimize import BFGS [as 別名]
def test_pwscf_calculator():
if not have_ase():
skip("no ASE found, skipping test")
elif not have_pwx():
skip("no pw.x found, skipping test")
else:
pseudo_dir = pj(testdir, prefix, 'pseudo')
print(common.backtick("mkdir -pv {p}; cp files/qe_pseudos/*.gz {p}/; \
gunzip {p}/*".format(p=pseudo_dir)))
at = get_atoms_with_calc_pwscf(pseudo_dir)
print("scf")
# trigger calculation here
forces = at.get_forces()
etot = at.get_potential_energy()
stress = at.get_stress(voigt=False) # 3x3
st = io.read_pw_scf(at.calc.label + '.out')
assert np.allclose(forces, st.forces)
assert np.allclose(etot, st.etot)
assert np.allclose(st.stress, -stress * constants.eV_by_Ang3_to_GPa)
# files/ase/pw.scf.out.start is a norm-conserving LDA struct,
# calculated with pz-vbc.UPF, so the PBE vc-relax will make the cell
# a bit bigger
print("vc-relax")
from ase.optimize import BFGS
from ase.constraints import UnitCellFilter
opt = BFGS(UnitCellFilter(at))
cell = parse.arr2d_from_txt("""
-1.97281509 0. 1.97281509
0. 1.97281509 1.97281509
-1.97281509 1.97281509 0.""")
assert np.allclose(cell, at.get_cell())
opt.run(fmax=0.05) # run only 2 steps
cell = parse.arr2d_from_txt("""
-2.01837531 0. 2.01837531
0. 2.01837531 2.01837531
-2.01837531 2.01837531 0""")
assert np.allclose(cell, at.get_cell())
# at least 1 backup files must exist: pw.*.0 is the SCF run, backed up
# in the first iter of the vc-relax
assert os.path.exists(at.calc.infile + '.0')