Esempio n. 1
0
 def testOptim(self):
     ff = PyXtal_FF(model={'system': ["Si"]}, logo=False)
     ff.run(mode='predict', mliap=bp_model)
     calc = PyXtalFFCalculator(ff=ff)
     si = bulk('Si', 'diamond', a=5.0, cubic=True)
     si.set_calculator(calc)
     si = optimize(si, box=True)
     self.assertTrue(abs(si.get_cell()[0][0] - 5.469) < 1e-2)
Esempio n. 2
0
    def test_6_LR_calculator(self):
        #calc = PyXtalFFCalculator(mliap='unittest/PolyReg-checkpoint.pth', logo=False)
        ff = PyXtal_FF(model={'system': ["Si"]}, logo=False)
        ff.run(mode='predict', mliap='unittest/PolyReg-checkpoint.pth')
        calc = PyXtalFFCalculator(ff=ff)

        self.struc.set_calculator(calc)
        self.struc.get_potential_energy()
        self.struc.get_stress()
Esempio n. 3
0
 def test_elastic(self):
     ff = PyXtal_FF(model={'system': ["Si"]}, logo=False)
     ff.run(mode='predict', mliap=bp_model)
     calc = PyXtalFFCalculator(ff=ff)
     si = bulk('Si', 'diamond', a=5.469, cubic=True)
     si.set_calculator(calc)
     C, C_err = fit_elastic_constants(si, symmetry='cubic', optimizer=BFGS)
     C /= units.GPa
     self.assertTrue(abs(C[0, 0] - 124.5) < 1.0)
Esempio n. 4
0

def printenergy(a, it, t0):
    """Function to print the potential, kinetic and total energy"""
    epot = a.get_potential_energy() / len(a)
    ekin = a.get_kinetic_energy() / len(a)
    t_now = time()
    print('Step: %4d [%6.2f]: Epot = %.3feV  Ekin = %.3feV (T=%3.0fK)  '
          'Etot = %.3feV ' % (\
          it, t_now-t0, epot, ekin, ekin / (1.5 * units.kB), epot + ekin))
    return t_now


ff = PyXtal_FF(model={'system': ["Si"]}, logo=False)
ff.run(mode='predict', mliap=options.file)
calc = PyXtalFFCalculator(ff=ff)

si = bulk('Si', 'diamond', a=5.659, cubic=True)
si = si * 5
print("MD simulation for ", len(si), " atoms")
si.set_calculator(calc)

MaxwellBoltzmannDistribution(si, 1000 * units.kB)
dyn = Langevin(si, timestep=5 * units.fs, temperature_K=1000, friction=0.02)
#dyn = VelocityVerlet(si, 5*units.fs)  # 2 fs time step.
t0 = time()
for i in range(10):
    dyn.run(steps=1)
    t_now = printenergy(si, i, t0)
    t0 = t_now
Esempio n. 5
0
des, folder = "sna", "SiO2-snap"
mliap  = folder + "/30-30-checkpoint.pth"
lmpiap = folder + "/NN_weights.txt"
lmpdes = folder + "/DescriptorParam.txt"


# initial silicon crystal
si = read('lt_quartz.cif')
# set the ordering
si.set_tags([2]*3+[1]*6) 
si.positions[0,0] += (random() - 0.5)

# ase pyxtal_ff calculator
ff = PyXtal_FF(model={'system': ["Si", "O"]}, logo=False)
ff.run(mode='predict', mliap=mliap)
calc_pff = PyXtalFFCalculator(ff=ff)

# ase lammps calculatoor
lammps_name=''
comm=None
log_file='lammps.log'
cmd_args = ['-echo', 'log', '-log', log_file,
            '-screen', 'none', '-nocite']
lmp = lammps(lammps_name, cmd_args, comm)

parameters = ["mass * 1.0",
              "pair_style mliap model nn " + lmpiap + " descriptor " + des + " " + lmpdes,
              "pair_coeff * * O Si"
              ]

calc_lmp = LAMMPSlib(lmp=lmp, lmpcmds=parameters)
Esempio n. 6
0
from pyxtal_ff import PyXtal_FF
from pyxtal_ff.calculator import PyXtalFFCalculator

import warnings
warnings.simplefilter("ignore")

des, folder = "sna", "Si-snap-zbl"
mliap = folder + "/12-12-checkpoint.pth"
lmpiap = folder + "/NN_weights.txt"
lmpdes = folder + "/DescriptorParam.txt"

# ase pyxtal_ff calculator
ff = PyXtal_FF(model={'system': ["Si"]}, logo=False)
ff.run(mode='predict', mliap=mliap)
calc = PyXtalFFCalculator(ff=ff, style='lammps')  #GPa, xx, yy, zz, xy, xz, yz

with connect(folder + '/ase.db') as db:
    print(len(db))
    maes = []
    for i, row in enumerate(db.select()):
        if "stress" in row.data and row.data["group"] == "Elastic":
            s = db.get_atoms(row.id)
            s.set_calculator(calc)
            e = s.get_potential_energy()
            s1 = row.data['stress']  # GPa
            s2 = s.get_stress()
            mae = np.mean(np.abs(s1 - s2))
            print(
                "\nDFT Energy: {:6.3f} v.s. PFF energy {:6.3f} S_MAE: {:6.3f}".
                format(row.data['energy'], e, mae))