예제 #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)
예제 #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()
예제 #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)
예제 #4
0
class TestRegression(unittest.TestCase):
    model = {
        'system': system,
        'hiddenlayers': [12, 12],
        'epoch': 10,
        'stress_coefficient': None,
        'force_coefficient': 0.03,
        'path': 'unittest/'
    }
    ff = PyXtal_FF(descriptors=descriptor, model=model)
    struc = bulk('Si', 'diamond', a=5.0, cubic=True)

    @classmethod
    def tearDownClass(cls):
        shutil.rmtree('unittest')

    def test_1_NN_LBFGS(self):
        self.ff.algorithm = 'NN'
        self.ff._model['optimizer'] = {'method': 'lbfgs'}
        (train_stat, _) = self.ff.run(mode='train', TrainData=TrainData)

    def test_2_NN_ADAM(self):
        self.ff.algorithm = 'NN'
        self.ff._model['optimizer'] = {'method': 'ADAM'}
        self.ff._MODEL(self.ff._model)
        train_stat = self.ff.model.train('Train_db', self.ff.optimizer)
        self.ff.model.save_checkpoint(des_info=self.ff._descriptors)

    def test_3_lr(self):
        self.ff.algorithm = 'PR'
        self.ff._model['order'] = 1
        self.ff._MODEL(self.ff._model)
        train_stat = self.ff.model.train('Train_db', None)
        self.ff.model.save_checkpoint(des_info=self.ff._descriptors)

    def test_4_qr(self):
        self.ff.algorithm = 'PR'
        self.ff._model['order'] = 2
        self.ff._MODEL(self.ff._model)
        train_stat = self.ff.model.train('Train_db', None)

    def test_5_NN_calculator(self):
        #calc = PyXtalFFCalculator(mliap='unittest/12-12-checkpoint.pth', logo=False)
        ff = PyXtal_FF(model={'system': ["Si"]}, logo=False)
        ff.run(mode='predict', mliap='unittest/12-12-checkpoint.pth')
        calc = PyXtalFFCalculator(ff=ff)

        self.struc.set_calculator(calc)
        self.struc.get_potential_energy()
        self.struc.get_stress()

    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()
예제 #5
0
class TestRegressionComp(unittest.TestCase):

    model = {'system' : system,
             'stress_coefficient': None,
             'force_coefficient': 0.03,
             'path': 'unittest_comp/',
             'algorithm': 'PR',
            }
    ff = PyXtal_FF(descriptors=descriptor_comp, model=model)

    @classmethod
    def tearDownClass(cls):
        shutil.rmtree('unittest_comp')
        
    def test_lr_comp(self):
        self.ff._model['order'] = 1
        (train_stat, _) = self.ff.run(mode='train', TrainData=TrainData)
예제 #6
0
        },
        'Rc': 5.0,
        'parameters': {
            'lmax': 4,
            'nmax': 3
        },
        'base_potential': {
            'inner': 1.5,
            'outer': 2.0
        },  #zbl potential
        'ncpu': 1,
    }

model = {
    'system': ['Si'],
    'hiddenlayers': [12, 12],
    'path': folder,
    #'restart': folder + '12-12-checkpoint.pth',
    'optimizer': {
        'method': 'lbfgs'
    },
    'force_coefficient': 2e-2,
    'stress_coefficient': 2e-3,
    "stress_group": ["Elastic"],
    'alpha': 1e-6,
    'epoch': 1000,
}

ff = PyXtal_FF(descriptors=descriptor, model=model)
ff.run(mode='train', TrainData=TrainData, TestData=TestData)
예제 #7
0
파일: md.py 프로젝트: qzhu2017/PyXtal_FF
(options, args) = parser.parse_args()


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)
예제 #8
0
warnings.simplefilter("ignore")

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"
              ]
예제 #9
0
    print('downloading the training data')
    os.system(
        'wget https://raw.githubusercontent.com/MDIL-SNU/SIMPLE-NN/master/examples/SiO2/ab_initio_output/OUTCAR_comp'
    )

descriptor = {
    'Rc': 4.9,
    'parameters': {
        'lmax': 3
    },
    'N_train': 250,
    'ncpu': 4,
}

model = {
    'system': ['Si', 'O'],
    'hiddenlayers': [30, 30],
    'activation': ['Tanh', 'Tanh', 'Linear'],
    'force_coefficient': 0.1,
    'epoch': 500,
    'path': 'SiO2-quick/',
    #'restart': 'SiO2-quick/30-30-checkpoint.pth',
    'optimizer': {
        'method': 'lbfgs'
    },
}

#------------------------- Run NN calculation ------------------------------
ff = PyXtal_FF(descriptors=descriptor, model=model)
ff.run(mode='train', TrainData=train_data)
예제 #10
0
    'ncpu': 1,
}
model = {
    'system': ['Si'],
    'hiddenlayers': [20, 20],
    'random_seed': 12345,
    'activation': ['Tanh', 'Tanh', 'Linear'],
    'optimizer': {
        'method': 'lbfgs'
    },
    'force_coefficient': 1.,
    'stress_coefficient': 1.,
    'alpha': 1e-6,
    'epoch': 500,
}
ff = PyXtal_FF(descriptors=descriptor, model=model)
ff.run(mode='train', TrainData=TrainData, TestData=None)
shutil.copyfile('Si-SNAP/20-20-checkpoint.pth', "potentials/Si-20-20-0K.pth")
shutil.rmtree('Si-SNAP')

Ts = [500, 750, 1000, 1250, 1500]
for i, T in enumerate(Ts):
    print("Temperature: ", T)
    ase_db = f"Si{T}.db"
    struc = bulk("Si", 'diamond', a=5.468728, cubic=True) * (2, 2, 2)
    struc.info['md_step'] = 0
    mliap = f'potentials/Si-20-20-0K.pth' if i == 0 else f'potentials/Si-20-20-{Ts[i-1]}K.pth'
    ff = PyXtal_FF(model={'system': ["Si"]}, logo=False)
    ff.run(mode='predict', mliap=mliap)
    calc = PyXtalFFCalculator(ff=ff)
    struc.set_calculator(calc)