def get_quantum_package_sim(**kwargs): from physical_system import generate_physical_system from machines import job from quantum_package import QuantumPackage,generate_quantum_package QuantumPackage.qprc = '' system = generate_physical_system( elem_pos = ''' O 0.000000 0.000000 0.000000 H 0.000000 0.757160 0.586260 H 0.000000 0.757160 -0.586260 ''', ) sim = generate_quantum_package( job = job(machine='ws1',cores=1), system = system, prefix = 'h2o', run_type = 'scf', **kwargs ) assert(isinstance(sim,QuantumPackage)) return sim
def test_kf_rpa(): from test_structure import example_structure_h4 from physical_system import generate_physical_system s1 = example_structure_h4() ps = generate_physical_system(structure=s1, net_charge=1, net_spin=1, H=1) kfs = ps.kf_rpa() assert np.isclose(kfs[0], 1.465, atol=1e-3) assert np.isclose(kfs[1], 1.465 / 2**(1. / 3), atol=1e-3)
def test_generate(): import os from generic import obj from physical_system import generate_physical_system from quantum_package_input import generate_quantum_package_input tpath = testing.setup_unit_test_output_directory('quantum_package_input', 'test_generate') # water molecule rhf xyz_path = os.path.join(tpath, 'H2O.xyz') open(xyz_path, 'w').write(h2o_xyz) system = generate_physical_system(structure=xyz_path, ) qi = generate_quantum_package_input( system=system, prefix='h2o', run_type='scf', ao_basis='cc-pvtz', ) check_vs_serial_reference(qi, 'h2o.ezfio gen') assert (qi.is_valid()) # O2 molecule selci xyz_path = os.path.join(tpath, 'O2.xyz') open(xyz_path, 'w').write(o2_xyz) system = generate_physical_system(structure=xyz_path, ) qi = generate_quantum_package_input( system=system, prefix='o2', run_type='fci', n_det_max=5000, save_natorb=True, four_idx_transform=True, ) check_vs_serial_reference(qi, 'o2.ezfio gen') assert (qi.is_valid())
def test_tile(): from physical_system import generate_physical_system d2_ref = generate_physical_system( units='A', axes=[[1.785, 1.785, 0.], [0., 1.785, 1.785], [1.785, 0., 1.785]], elem=2 * ['C'], posu=[[0.00, 0.00, 0.00], [0.25, 0.25, 0.25]], C=4, ) d8_ref = generate_physical_system( units='A', axes=[[1.785, 1.785, 0.], [0., 1.785, 1.785], [1.785, 0., 1.785]], elem=2 * ['C'], posu=[[0.00, 0.00, 0.00], [0.25, 0.25, 0.25]], tiling=[[1, -1, 1], [1, 1, -1], [-1, 1, 1]], C=4, ) d8 = d2_ref.tile([[1, -1, 1], [1, 1, -1], [-1, 1, 1]]) assert (system_same(d8, d8_ref, tiled=True))
def setup_vasp_sim(path, identifier='vasp', files=False): import shutil from nexus_base import nexus_core from machines import job from physical_system import generate_physical_system from vasp import generate_vasp, Vasp copy_files = files del files nexus_core.runs = '' files = get_files() dia16 = generate_physical_system(structure=files['d16bulk.POSCAR'], C=4) sim = generate_vasp( identifier=identifier, path=path, job=job(machine='ws1', cores=1), system=dia16, pseudos=['C.POTCAR'], input_type='generic', istart=0, icharg=2, encut=450, nsw=5, ibrion=2, isif=2, kcenter='monkhorst', kgrid=(2, 2, 2), kshift=(0, 0, 0), ) assert (isinstance(sim, Vasp)) if copy_files: vfiles = [ 'diamond_INCAR', 'diamond_KPOINTS', 'diamond_POSCAR', 'diamond_POTCAR', ] for vfile in vfiles: shutil.copy2(files[vfile], path) #end for #end if return sim
def get_system(tiling=(1, 1, 1)): from physical_system import generate_physical_system system = generate_physical_system( units='A', axes=[[1.785, 1.785, 0.], [0., 1.785, 1.785], [1.785, 0., 1.785]], elem=['C', 'C'], pos=[[0., 0., 0.], [0.8925, 0.8925, 0.8925]], tiling=tiling, kgrid=(1, 1, 1), kshift=(0, 0, 0), #C = 4 ) return system
def test_generate(): import os from nexus_base import nexus_noncore from physical_system import generate_physical_system from vasp_input import generate_vasp_input, VaspInput tpath = testing.setup_unit_test_output_directory('vasp_input', 'test_generate', divert=True) pseudo_dir = os.path.join(tpath, 'pseudopotentials') nexus_noncore.pseudo_dir = pseudo_dir if not os.path.exists(pseudo_dir): os.makedirs(pseudo_dir) #end if open(os.path.join(pseudo_dir, 'C.POTCAR'), 'w').write(c_potcar_text) files = get_files() dia16 = generate_physical_system(structure=files['d16bulk.POSCAR'], C=4) vi = generate_vasp_input( system=dia16, pseudos=['C.POTCAR'], input_type='generic', istart=0, icharg=2, encut=450, nsw=5, ibrion=2, isif=2, kcenter='monkhorst', kgrid=(2, 2, 2), kshift=(0, 0, 0), ) assert (isinstance(vi, VaspInput)) del vi.potcar.filepath check_vs_serial_reference(vi, 'generate') restore_nexus()
def test_change_units(): from physical_system import generate_physical_system sys = generate_physical_system( units='A', axes=[[3.57, 0.00, 0.00], [0.00, 3.57, 0.00], [0.00, 0.00, 3.57]], elem=8 * ['C'], posu=[[0.00, 0.00, 0.00], [0.25, 0.25, 0.25], [0.00, 0.50, 0.50], [0.25, 0.75, 0.75], [0.50, 0.00, 0.50], [0.75, 0.25, 0.75], [0.50, 0.50, 0.00], [0.75, 0.75, 0.25]], C=4, ) s = sys.structure assert (value_eq(s.pos[-1], np.array([2.6775, 2.6775, 0.8925]))) sys.change_units('B') assert (value_eq(s.pos[-1], np.array([5.05974172, 5.05974172, 1.68658057])))
def test_rename(): from generic import obj from physical_system import generate_physical_system sys = generate_physical_system( units='A', axes=[[1.785, 1.785, 0.], [0., 1.785, 1.785], [1.785, 0., 1.785]], elem=['C1', 'C2'], posu=[[0.00, 0.00, 0.00], [0.25, 0.25, 0.25]], tiling=[[1, -1, 1], [1, 1, -1], [-1, 1, 1]], C1=4, C2=4, ) ref = sys assert (object_eq(ref.valency, obj(C1=4, C2=4))) assert (list(ref.structure.elem) == 4 * ['C1', 'C2']) assert (ref.particles.count_ions() == 8) assert (ref.particles.count_ions(species=True) == (8, 2)) ref = sys.folded_system assert (object_eq(ref.valency, obj(C1=4, C2=4))) assert (list(ref.structure.elem) == ['C1', 'C2']) assert (ref.particles.count_ions() == 2) assert (ref.particles.count_ions(species=True) == (2, 2)) sys.rename(C1='C', C2='C') ref = sys assert (object_eq(ref.valency, obj(C=4))) assert (list(ref.structure.elem) == 8 * ['C']) assert (ref.particles.count_ions() == 8) assert (ref.particles.count_ions(species=True) == (8, 1)) ref = sys.folded_system assert (object_eq(ref.valency, obj(C=4))) assert (list(ref.structure.elem) == 2 * ['C']) assert (ref.particles.count_ions() == 2) assert (ref.particles.count_ions(species=True) == (2, 1))
def test_generate(): import os from generic import obj from nexus_base import nexus_noncore from pseudopotential import Pseudopotentials from physical_system import generate_physical_system from gamess_input import generate_gamess_input ppfiles = ['H.BFD_V5Z_ANO.gms','O.BFD_V5Z.gms'] tpath = testing.setup_unit_test_output_directory( test = 'gamess_input', subtest = 'test_generate', divert = True, file_sets = { 'pseudopotentials':ppfiles } ) ppfiles_full = [os.path.join(tpath,'pseudopotentials',f) for f in ppfiles] nexus_noncore.pseudopotentials = Pseudopotentials(ppfiles_full) input_files = ['rhf.inp','cisd.inp','cas.inp'] h2o = generate_physical_system( elem = ['O','H','H'], pos = [[0.000000, 0.000000, 0.000000], [0.000000,-0.757160, 0.586260], [0.000000, 0.757160, 0.586260]], units = 'A', net_spin = 0, O = 6, H = 1, # C2v symmetry structure folded_elem = ['O','H'], folded_pos = [[0.000000, 0.000000, 0.000000], [0.000000, 0.757160, 0.586260]], ) inputs = dict() inputs['rhf.inp'] = obj( system = h2o, pseudos = ppfiles, scftyp = 'rohf', runtyp = 'energy', exetyp = 'run', ispher = 1, maxit = 200, memory = 150000000, dirscf = True, guess = 'huckel', symmetry = 'Cnv 2', ) inputs['cisd.inp'] = obj( system = h2o, pseudos = ppfiles, scftyp = 'none', cityp = 'guga', runtyp = 'energy', exetyp = 'run', ispher = 1, maxit = 200, memory = 150000000, dirscf = True, symmetry = 'Cnv 2', cidrt = obj( group = 'c2v', nfzc = 0, ndoc = 4, nalp = 0, nval = 60, nprt = 2, istsym = 1, iexcit = 2, mxnint = 500000, ), gugdia = obj( prttol = 0.001, cvgtol = 1.0e-5, itermx = 1000, ), ) inputs['cas.inp'] = obj( system = h2o, pseudos = ppfiles, scftyp = 'mcscf', runtyp = 'energy', exetyp = 'run', ispher = 1, maxit = 200, memory = 150000000, dirscf = True, symmetry = 'Cnv 2', drt = obj( group = 'c2v', nmcc = 0, ndoc = 4, nalp = 0, nval = 4, istsym = 1, mxnint = 500000, fors = True, ), mcscf = obj( cistep = 'guga', maxit = 1000, fullnr = True, acurcy = 1e-5, ), ) for infile in input_files: gi = generate_gamess_input(**inputs[infile]) check_vs_serial_reference(gi,infile) #end for restore_nexus()
def test_generate(): import os from generic import obj from physical_system import generate_physical_system from pyscf_input import generate_pyscf_input tpath = testing.setup_unit_test_output_directory('pyscf_input','test_generate') # water molecule xyz_path = os.path.join(tpath,'H2O.xyz') template_path = os.path.join(tpath,'scf_template.py') open(xyz_path,'w').write(h2o_xyz) open(template_path,'w').write(scf_template) system = generate_physical_system( structure = xyz_path, ) pi = generate_pyscf_input( template = template_path, system = system, mole = obj( basis = 'ccpvtz', symmetry = True, ), ) ref_system = ''' ### generated system text ### from pyscf import gto as gto_loc mol = gto_loc.Mole() mol.atom = {0} O 0.00000000 0.00000000 0.00000000 H 0.00000000 0.75716000 0.58626000 H 0.00000000 0.75716000 -0.58626000 {0} mol.basis = 'ccpvtz' mol.unit = 'A' mol.charge = 0 mol.spin = 0 mol.symmetry = True mol.build() ### end generated system text ### '''.format("'''") assert(pi.template is not None) assert(len(pi.values)==1 and 'system' in pi.values) assert(text_eq(pi.values.system,ref_system)) ref_internal = obj( addendum = None, allow_not_set = set([]), checkpoint = False, keywords = set(['system']), prefix = None, save_qmc = False, ) del pi.template del pi.values assert(object_eq(pi.to_obj(),ref_internal)) # diamond crystal system = generate_physical_system( units = 'A', axes = '''1.785 1.785 0.000 0.000 1.785 1.785 1.785 0.000 1.785''', elem_pos = ''' C 0.0000 0.0000 0.0000 C 0.8925 0.8925 0.8925 ''', kgrid = (1,1,1), kshift = (0,0,0), C = 4, ) pi = generate_pyscf_input( template = template_path, system = system, cell = obj( basis = 'bfd-vdz', ecp = 'bfd', drop_exponent = 0.1, verbose = 5, ), ) ref_system = ''' ### generated system text ### from numpy import array from pyscf.pbc import gto as gto_loc cell = gto_loc.Cell() cell.a = {0} 1.78500000 1.78500000 0.00000000 0.00000000 1.78500000 1.78500000 1.78500000 0.00000000 1.78500000 {0} cell.basis = 'bfd-vdz' cell.dimension = 3 cell.ecp = 'bfd' cell.unit = 'A' cell.atom = {0} C 0.00000000 0.00000000 0.00000000 C 0.89250000 0.89250000 0.89250000 {0} cell.drop_exponent = 0.1 cell.verbose = 5 cell.charge = 0 cell.spin = 0 cell.build() kpts = array([ [0.0, 0.0, 0.0]]) ### end generated system text ### '''.format("'''") assert(pi.template is not None) assert(len(pi.values)==1 and 'system' in pi.values) assert(text_eq(pi.values.system,ref_system)) del pi.template del pi.values assert(object_eq(pi.to_obj(),ref_internal)) # water molecule without template xyz_path = os.path.join(tpath,'H2O.xyz') open(xyz_path,'w').write(h2o_xyz) system = generate_physical_system( structure = xyz_path, ) pi = generate_pyscf_input( system = system, mole = obj( basis = 'ccpvtz', symmetry = True, ), calculation = obj( method = 'RHF', df_fitting = False, ), ) ref_system = ''' ### generated system text ### from pyscf import gto as gto_loc mol = gto_loc.Mole() mol.atom = {0} O 0.00000000 0.00000000 0.00000000 H 0.00000000 0.75716000 0.58626000 H 0.00000000 0.75716000 -0.58626000 {0} mol.basis = 'ccpvtz' mol.unit = 'A' mol.charge = 0 mol.spin = 0 mol.symmetry = True mol.build() ### end generated system text ### '''.format("'''") ref_calculation = ''' ### generated calculation text ### mf = scf.RHF(mol) mf.tol = '1e-10' e_scf = mf.kernel() ### end generated calculation text ### '''.format("'''") ref_pyscfimport = ''' ### generated pyscfimport text ### from pyscf import df, scf, dft ### end generated pyscfimport text ### '''.format("'''") ref_python_exe = 'python' assert(len(pi.values)==4 and 'system' in pi.values) assert(len(pi.values)==4 and 'calculation' in pi.values) assert(len(pi.values)==4 and 'pyscfimport' in pi.values) assert(len(pi.values)==4 and 'python_exe' in pi.values) assert(text_eq(pi.values.system,ref_system)) assert(text_eq(pi.values.calculation,ref_calculation)) assert(text_eq(pi.values.pyscfimport,ref_pyscfimport)) assert(text_eq(pi.values.python_exe,ref_python_exe)) ref_internal = obj( addendum = None, allow_not_set = set([]), checkpoint = False, keywords = set(['system','calculation','pyscfimport','python_exe']), prefix = None, save_qmc = False, ) del pi.values del pi.calculation del pi.template assert(object_eq(pi.to_obj(),ref_internal)) # MnO crystal without template poscar_path = os.path.join(tpath,'MnO.POSCAR') open(poscar_path,'w').write(mno_poscar) system = generate_physical_system( structure = poscar_path, elem = ['O','Mn'], O = 6, Mn = 15, tiling = (1,1,1), kgrid = (1,1,1), kshift = (0,0,0), ) pi = generate_pyscf_input( system = system, cell = obj( basis = 'bfd-vdz', ecp = 'bfd', drop_exponent = 0.1, verbose = 5, ), python_exe = 'python3', calculation = obj( method = 'KRKSpU', df_fitting = True, xc = 'pbe', tol = '1e-10', df_method = 'GDF', exxdiv = 'ewald', u_idx = ['Mn 3d'], u_val = [2.0], C_ao_lo = 'minao', ), ) ref_system = """ ### generated system text ### from numpy import array from pyscf.pbc import gto as gto_loc cell = gto_loc.Cell() cell.a = ''' 4.49453800 0.00000000 0.00000000 0.00000000 4.49453800 0.00000000 0.00000000 0.00000000 4.49453800 ''' cell.basis = 'bfd-vdz' cell.dimension = 3 cell.ecp = 'bfd' cell.unit = 'A' cell.atom = ''' O 0.00000000 0.00000000 10.10043601 O 0.00000000 10.10043601 0.00000000 O 10.10043601 0.00000000 0.00000000 O 10.10043601 10.10043601 10.10043601 Mn 0.00000000 0.00000000 0.00000000 Mn 0.00000000 10.10043601 10.10043601 Mn 10.10043601 0.00000000 10.10043601 Mn 10.10043601 10.10043601 0.00000000 ''' cell.drop_exponent = 0.1 cell.verbose = 5 cell.charge = 0 cell.spin = 0 cell.build() kpts = array([ [0.0, 0.0, 0.0]]) ### end generated system text ### """.format("'''") ref_calculation = ''' ### generated calculation text ### mydf = df.GDF(cell) mydf.auxbasis = 'weigend' dfpath = 'df_ints.h5' mydf._cderi_to_save = dfpath mydf.build() mf = dft.KRKSpU(cell,kpts,U_idx=array(['Mn 3d']),U_val=array([2.0]),C_ao_lo='minao').density_fit() mf.exxdiv = 'ewald' mf.xc = 'pbe' mf.tol = '1e-10' mf.with_df = mydf e_scf = mf.kernel() ### end generated calculation text ### '''.format("'''") ref_pyscfimport = ''' ### generated pyscfimport text ### from pyscf.pbc import df, scf ### end generated pyscfimport text ### '''.format("'''") ref_python_exe = 'python3' assert(len(pi.values)==4 and 'system' in pi.values) assert(len(pi.values)==4 and 'calculation' in pi.values) assert(len(pi.values)==4 and 'pyscfimport' in pi.values) assert(len(pi.values)==4 and 'python_exe' in pi.values) assert(text_eq(pi.values.system,ref_system)) assert(text_eq(pi.values.calculation,ref_calculation)) assert(text_eq(pi.values.pyscfimport,ref_pyscfimport)) assert(text_eq(pi.values.python_exe,ref_python_exe)) ref_internal = obj( addendum = None, allow_not_set = set([]), checkpoint = False, keywords = set(['system','calculation','pyscfimport','python_exe']), prefix = None, save_qmc = False, ) del pi.values del pi.calculation del pi.template assert(object_eq(pi.to_obj(),ref_internal))
def test_write(): import os from generic import obj from physical_system import generate_physical_system from pyscf_input import generate_pyscf_input tpath = testing.setup_unit_test_output_directory('pyscf_input','test_write') # water molecule xyz_path = os.path.join(tpath,'H2O.xyz') template_path = os.path.join(tpath,'scf_template.py') open(xyz_path,'w').write(h2o_xyz) open(template_path,'w').write(scf_template) system = generate_physical_system( structure = xyz_path, ) pi = generate_pyscf_input( prefix = 'scf', template = template_path, system = system, mole = obj( verbose = 5, basis = 'ccpvtz', symmetry = True, ), save_qmc = True, ) write_path = os.path.join(tpath,'h2o.py') pi.write(write_path) assert(os.path.exists(write_path)) text = open(write_path,'r').read() ref_text = ''' #! /usr/bin/env python3 from pyscf import scf ### generated system text ### from pyscf import gto as gto_loc mol = gto_loc.Mole() mol.verbose = 5 mol.atom = {0} O 0.00000000 0.00000000 0.00000000 H 0.00000000 0.75716000 0.58626000 H 0.00000000 0.75716000 -0.58626000 {0} mol.basis = 'ccpvtz' mol.unit = 'A' mol.charge = 0 mol.spin = 0 mol.symmetry = True mol.build() ### end generated system text ### mf = scf.RHF(mol) mf.kernel() ### generated conversion text ### from PyscfToQmcpack import savetoqmcpack savetoqmcpack(mol,mf,'scf') ### end generated conversion text ### '''.format("'''") assert(text_eq(text,ref_text)) # diamond crystal system = generate_physical_system( units = 'A', axes = '''1.785 1.785 0.000 0.000 1.785 1.785 1.785 0.000 1.785''', elem_pos = ''' C 0.0000 0.0000 0.0000 C 0.8925 0.8925 0.8925 ''', tiling = (2,1,1), kgrid = (1,1,1), kshift = (0,0,0), C = 4, ) pi = generate_pyscf_input( prefix = 'scf', template = template_path, system = system, cell = obj( basis = 'bfd-vdz', ecp = 'bfd', drop_exponent = 0.1, verbose = 5, ), save_qmc = True, ) write_path = os.path.join(tpath,'diamond.py') pi.write(write_path) assert(os.path.exists(write_path)) text = open(write_path,'r').read() ref_text = ''' #! /usr/bin/env python3 from pyscf import scf ### generated system text ### from numpy import array from pyscf.pbc import gto as gto_loc cell = gto_loc.Cell() cell.a = {0} 1.78500000 1.78500000 0.00000000 0.00000000 1.78500000 1.78500000 1.78500000 0.00000000 1.78500000 {0} cell.basis = 'bfd-vdz' cell.dimension = 3 cell.ecp = 'bfd' cell.unit = 'A' cell.atom = {0} C 0.00000000 0.00000000 0.00000000 C 0.89250000 0.89250000 0.89250000 {0} cell.drop_exponent = 0.1 cell.verbose = 5 cell.charge = 0 cell.spin = 0 cell.build() kpts = array([ [0.0, 0.0, 0.0] , [0.4656748546088228, 0.4656748546088228, -0.4656748546088228]]) ### end generated system text ### mf = scf.RHF(mol) mf.kernel() ### generated conversion text ### from PyscfToQmcpack import savetoqmcpack savetoqmcpack(cell,mf,'scf',kpts) ### end generated conversion text ### '''.format("'''") text = text.replace('[',' [ ').replace(']',' ] ') ref_text = ref_text.replace('[',' [ ').replace(']',' ] ') assert(text_eq(text,ref_text))
def test_physical_system_initialization(): import os from generic import obj from structure import generate_structure from physical_system import generate_physical_system from physical_system import PhysicalSystem tpath = testing.setup_unit_test_output_directory( 'physical_system', 'test_physical_system_initialization') d2 = generate_structure( structure='diamond', cell='prim', ) d2_path = os.path.join(tpath, 'diamond2.xsf') d2.write(d2_path) d8 = generate_structure( structure='diamond', cell='conv', ) d8_path = os.path.join(tpath, 'diamond8.xsf') d8.write(d8_path) d8_tile = d2.tile([[1, -1, 1], [1, 1, -1], [-1, 1, 1]]) d8_tile_pos_ref = np.array([[0., 0., 0.], [0.25, 0.25, 0.25], [0.5, 0.5, 0.], [0.75, 0.75, 0.25], [0., 0.5, 0.5], [0.25, 0.75, 0.75], [0.5, 0., 0.5], [0.75, 0.25, 0.75]]) assert (value_eq(d8_tile.pos_unit(), d8_tile_pos_ref, atol=1e-8)) direct_notile = generate_physical_system( units='A', axes=[[3.57, 0.00, 0.00], [0.00, 3.57, 0.00], [0.00, 0.00, 3.57]], elem=8 * ['C'], posu=[[0.00, 0.00, 0.00], [0.25, 0.25, 0.25], [0.00, 0.50, 0.50], [0.25, 0.75, 0.75], [0.50, 0.00, 0.50], [0.75, 0.25, 0.75], [0.50, 0.50, 0.00], [0.75, 0.75, 0.25]], C=4, ) direct_tile = generate_physical_system( units='A', axes=[[1.785, 1.785, 0.], [0., 1.785, 1.785], [1.785, 0., 1.785]], elem=2 * ['C'], posu=[[0.00, 0.00, 0.00], [0.25, 0.25, 0.25]], tiling=[[1, -1, 1], [1, 1, -1], [-1, 1, 1]], C=4, ) struct_notile = generate_physical_system( structure=d8, C=4, ) struct_tile = generate_physical_system( structure=d2, tiling=[[1, -1, 1], [1, 1, -1], [-1, 1, 1]], C=4, ) read_notile = generate_physical_system( structure=d8_path, C=4, ) read_tile = generate_physical_system( structure=d2_path, tiling=[[1, -1, 1], [1, 1, -1], [-1, 1, 1]], C=4, ) gen_notile = generate_physical_system( lattice='cubic', # cubic tetragonal orthorhombic rhombohedral # hexagonal triclinic monoclinic cell='conventional', # primitive, conventional centering='F', # P A B C I R F constants=3.57, # a,b,c,alpha,beta,gamma units='A', # A or B atoms='C', # species in primitive cell basis=[ [0, 0, 0], # basis vectors (optional) [.25, .25, .25] ], C=4, ) gen_tile = generate_physical_system( lattice='cubic', # cubic tetragonal orthorhombic rhombohedral # hexagonal triclinic monoclinic cell='primitive', # primitive, conventional centering='F', # P A B C I R F constants=3.57, # a,b,c,alpha,beta,gamma units='A', # A or B atoms='C', # species in primitive cell basis=[ [0, 0, 0], # basis vectors (optional) [.25, .25, .25] ], tiling=[[1, -1, 1], [1, 1, -1], [-1, 1, 1]], C=4, ) lookup_notile = generate_physical_system( structure='diamond', cell='conv', C=4, ) lookup_tile = generate_physical_system( structure='diamond', cell='prim', tiling=[[1, -1, 1], [1, 1, -1], [-1, 1, 1]], C=4, ) pref = obj( C=obj( charge=4, core_electrons=2, count=8, mass=21894.7135906, name='C', neutrons=6, protons=6, spin=0, ), down_electron=obj( charge=-1, count=16, mass=1.0, name='down_electron', spin=-1, ), up_electron=obj( charge=-1, count=16, mass=1.0, name='up_electron', spin=1, ), ) # check direct system w/o tiling ref = direct_notile sref = ref.structure assert (ref.net_charge == 0) assert (ref.net_spin == 0) assert (ref.pseudized) assert (object_eq(ref.valency, obj(C=4))) assert (object_eq(ref.particles.to_obj(), pref)) assert (structure_same(sref, d8)) assert (value_eq(sref.axes, 3.57 * np.eye(3))) assert (tuple(sref.bconds) == tuple('ppp')) assert (list(sref.elem) == 8 * ['C']) assert (value_eq(tuple(sref.pos[-1]), (2.6775, 2.6775, 0.8925))) assert (sref.units == 'A') assert (object_eq(ref.particles.get_ions().to_obj(), obj(C=pref.C))) assert (object_eq( ref.particles.get_electrons().to_obj(), obj(down_electron=pref.down_electron, up_electron=pref.up_electron))) # check direct system w/ tiling ref = direct_tile sref = ref.structure assert (ref.net_charge == 0) assert (ref.net_spin == 0) assert (ref.pseudized) assert (object_eq(ref.valency, obj(C=4))) assert (object_eq(ref.particles.to_obj(), pref)) assert (structure_same(sref, d8_tile)) assert (value_eq(sref.axes, 3.57 * np.eye(3))) assert (tuple(sref.bconds) == tuple('ppp')) assert (list(sref.elem) == 8 * ['C']) assert (value_eq(tuple(sref.pos[-1]), (2.6775, 0.8925, 2.6775))) assert (sref.units == 'A') ref = direct_tile.folded_system sref = ref.structure pref.C.count = 2 pref.down_electron.count = 4 pref.up_electron.count = 4 assert (ref.net_charge == 0) assert (ref.net_spin == 0) assert (ref.pseudized) assert (object_eq(ref.valency, obj(C=4))) assert (object_eq(ref.particles.to_obj(), pref)) assert (structure_same(sref, d2)) assert (value_eq(sref.axes, 1.785 * np.array([[1., 1, 0], [0, 1, 1], [1, 0, 1]]))) assert (tuple(sref.bconds) == tuple('ppp')) assert (list(sref.elem) == 2 * ['C']) assert (value_eq(tuple(sref.pos[-1]), (0.8925, 0.8925, 0.8925))) assert (sref.units == 'A') ref_notile = direct_notile ref_tile = direct_tile assert (system_same(struct_notile, ref_notile)) assert (system_same(read_notile, ref_notile)) assert (system_same(gen_notile, ref_notile)) assert (system_same(lookup_notile, ref_notile)) assert (system_same(struct_tile, ref_tile, tiled=True)) assert (system_same(read_tile, ref_tile, tiled=True)) assert (system_same(gen_tile, ref_tile, tiled=True)) assert (system_same(lookup_tile, ref_tile, tiled=True)) systems_notile = [ direct_notile, struct_notile, read_notile, gen_notile, lookup_notile, ] systems_tile = [ direct_tile, struct_tile, read_tile, gen_tile, lookup_tile, ] systems = systems_notile + systems_tile for sys in systems: assert (sys.is_valid()) #end for # test has_folded for sys in systems_notile: assert (not sys.has_folded()) #end for for sys in systems_tile: assert (sys.has_folded()) #end for # test copy for sys in systems: c = sys.copy() assert (id(c) != id(sys)) assert (c.is_valid()) assert (system_same(c, sys, tiled=sys.has_folded())) #end for # test load for i, sys in enumerate(systems): path = os.path.join(tpath, 'system_{}'.format(i)) sys.save(path) sys2 = PhysicalSystem() sys2.load(path) assert (sys2.is_valid()) assert (system_same(sys2, sys, tiled=sys.has_folded())) #end for # test particle counts p = direct_notile.particles assert (p.count_ions() == 8) assert (p.count_ions(species=True) == (8, 1)) assert (p.count_electrons() == 32) assert (p.electron_counts() == [16, 16])
def test_generate(): import os from generic import obj from physical_system import generate_physical_system from pyscf_input import generate_pyscf_input tpath = testing.setup_unit_test_output_directory('pyscf_input', 'test_generate') # water molecule xyz_path = os.path.join(tpath, 'H2O.xyz') template_path = os.path.join(tpath, 'scf_template.py') open(xyz_path, 'w').write(h2o_xyz) open(template_path, 'w').write(scf_template) system = generate_physical_system(structure=xyz_path, ) pi = generate_pyscf_input( template=template_path, system=system, mole=obj( basis='ccpvtz', symmetry=True, ), ) ref_system = ''' ### generated system text ### from pyscf import gto as gto_loc mol = gto_loc.Mole() mol.atom = {0} O 0.00000000 0.00000000 0.00000000 H 0.00000000 0.75716000 0.58626000 H 0.00000000 0.75716000 -0.58626000 {0} mol.basis = 'ccpvtz' mol.unit = 'A' mol.charge = 0 mol.spin = 0 mol.symmetry = True mol.build() ### end generated system text ### '''.format("'''") assert (pi.template is not None) assert (len(pi.values) == 1 and 'system' in pi.values) assert (text_eq(pi.values.system, ref_system)) ref_internal = obj( addendum=None, allow_not_set=set([]), checkpoint=False, keywords=set(['system']), prefix=None, save_qmc=False, ) del pi.template del pi.values assert (object_eq(pi.to_obj(), ref_internal)) # diamond crystal system = generate_physical_system( units='A', axes='''1.785 1.785 0.000 0.000 1.785 1.785 1.785 0.000 1.785''', elem_pos=''' C 0.0000 0.0000 0.0000 C 0.8925 0.8925 0.8925 ''', kgrid=(1, 1, 1), kshift=(0, 0, 0), C=4, ) pi = generate_pyscf_input( template=template_path, system=system, cell=obj( basis='bfd-vdz', ecp='bfd', drop_exponent=0.1, verbose=5, ), ) ref_system = ''' ### generated system text ### from numpy import array from pyscf.pbc import gto as gto_loc cell = gto_loc.Cell() cell.a = {0} 1.78500000 1.78500000 0.00000000 0.00000000 1.78500000 1.78500000 1.78500000 0.00000000 1.78500000 {0} cell.basis = 'bfd-vdz' cell.dimension = 3 cell.ecp = 'bfd' cell.unit = 'A' cell.atom = {0} C 0.00000000 0.00000000 0.00000000 C 0.89250000 0.89250000 0.89250000 {0} cell.drop_exponent = 0.1 cell.verbose = 5 cell.charge = 0 cell.spin = 0 cell.build() kpts = array([ [0.0, 0.0, 0.0]]) ### end generated system text ### '''.format("'''") assert (pi.template is not None) assert (len(pi.values) == 1 and 'system' in pi.values) assert (text_eq(pi.values.system, ref_system)) del pi.template del pi.values assert (object_eq(pi.to_obj(), ref_internal))
def test_input(): # imports import os import numpy as np import pwscf_input as pwi from generic import obj from structure import read_structure from physical_system import generate_physical_system from pwscf_input import check_new_variables,check_section_classes from pwscf_input import PwscfInput,generate_pwscf_input # directories tpath = testing.setup_unit_test_output_directory('pwscf_input','test_input') # files files = get_files() # divert logging function divert_nexus_log() # definitions def check_pw_same(pw1_,pw2_,l1='pw1',l2='pw2'): pw_same = object_eq(pw1_,pw2_,int_as_float=True) if not pw_same: d,d1,d2 = object_diff(pw1_,pw2_,full=True,int_as_float=True) diff = obj({l1:obj(d1),l2:obj(d2)}) failed(str(diff)) #end if #end def check_pw_same # test internal spec check_new_variables(exit=False) check_section_classes(exit=False) # test compose compositions = obj() # based on sample_inputs/Fe_start_ns_eig.in pw = PwscfInput() pw.control.set( calculation = 'scf' , restart_mode = 'from_scratch' , wf_collect = True , outdir = './output' , pseudo_dir = '../pseudo/' , prefix = 'fe' , etot_conv_thr = 1.0e-9 , forc_conv_thr = 1.0e-6 , tstress = True , tprnfor = True , ) pw.system.set( ibrav = 1, nat = 2, ntyp = 1, ecutwfc = 100 , ecutrho = 300 , nbnd = 18, occupations = 'smearing', degauss = 0.0005 , smearing = 'methfessel-paxton' , nspin = 2 , assume_isolated = 'martyna-tuckerman', lda_plus_u = True , ) pw.system.set({ 'celldm(1)' : 15, 'starting_magnetization(1)' : 0.9, 'hubbard_u(1)' : 3.1, 'starting_ns_eigenvalue(1,2,1)' : 0.0, 'starting_ns_eigenvalue(2,2,1)' : 0.0476060, 'starting_ns_eigenvalue(3,2,1)' : 0.0476060, 'starting_ns_eigenvalue(4,2,1)' : 0.9654373, 'starting_ns_eigenvalue(5,2,1)' : 0.9954307, }) pw.electrons.set( conv_thr = 1.0e-9 , mixing_beta = 0.7 , diagonalization = 'david' , mixing_fixed_ns = 500, ) pw.atomic_species.set( atoms = ['Fe'], masses = obj(Fe=58.69000), pseudopotentials = obj(Fe='Fe.pbe-nd-rrkjus.UPF'), ) pw.atomic_positions.set( specifier = 'angstrom', atoms = ['Fe','Fe'], positions = np.array([ [2.070000000, 0.000000000, 0.000000000], [0.000000000, 0.000000000, 0.000000000], ]), ) pw.k_points.set( specifier = 'automatic', grid = np.array((1,1,1)), shift = np.array((1,1,1)), ) compositions['Fe_start_ns_eig.in'] = pw # test read pwr = PwscfInput(files['Fe_start_ns_eig.in']) pwc = pw.copy() pwc.standardize_types() check_pw_same(pwc,pwr,'compose','read') # test write infile = os.path.join(tpath,'pwscf.in') pw.write(infile) pw2 = PwscfInput() pw2.read(infile) check_pw_same(pw2,pwr) # test read/write/read reads = obj() for infile in input_files: read_path = files[infile] write_path = os.path.join(tpath,infile) if os.path.exists(write_path): os.remove(write_path) #end if pw = PwscfInput(read_path) pw.write(write_path) pw2 = PwscfInput(write_path) check_pw_same(pw,pw2,'read','write/read') reads[infile] = pw #end for # test generate generations = obj() # based on sample_inputs/VO2_M1_afm.in infile = 'VO2_M1_afm.in' struct_file = files['VO2_M1_afm.xsf'] read_path = files[infile] write_path = os.path.join(tpath,infile) s = read_structure(struct_file) s.elem[0] = 'V1' s.elem[1] = 'V2' s.elem[2] = 'V1' s.elem[3] = 'V2' vo2 = generate_physical_system( structure = s, V1 = 13, V2 = 13, O = 6, ) pw = generate_pwscf_input( selector = 'generic', calculation = 'scf', disk_io = 'low', verbosity = 'high', wf_collect = True, input_dft = 'lda', hubbard_u = obj(V1=3.5,V2=3.5), ecutwfc = 350, bandfac = 1.3, nosym = True, occupations = 'smearing', smearing = 'fermi-dirac', degauss = 0.0001, nspin = 2, start_mag = obj(V1=1.0,V2=-1.0), diagonalization = 'david', conv_thr = 1e-8, mixing_beta = 0.2, electron_maxstep = 1000, system = vo2, pseudos = ['V.opt.upf','O.opt.upf'], kgrid = (6,6,6), kshift = (0,0,0), # added for reverse compatibility celldm = {1:1.0}, cell_option = 'alat', positions_option = 'alat', ) generations[infile] = pw if os.path.exists(write_path): os.remove(write_path) #end if pw.write(write_path) pw2 = PwscfInput(read_path) pw3 = PwscfInput(write_path) check_pw_same(pw2,pw3,'generate','read') # based on sample_inputs/Fe_start_ns_eig.in infile = 'Fe_start_ns_eig.in' read_path = files[infile] write_path = os.path.join(tpath,infile) pw = generate_pwscf_input( selector = 'generic', calculation = 'scf', restart_mode = 'from_scratch', wf_collect = True, outdir = './output', pseudo_dir = '../pseudo/', prefix = 'fe', etot_conv_thr = 1.0e-9, forc_conv_thr = 1.0e-6, tstress = True, tprnfor = True, ibrav = 1, nat = 2, ntyp = 1, ecutwfc = 100, ecutrho = 300, nbnd = 18, occupations = 'smearing', degauss = 0.0005, smearing = 'methfessel-paxton', nspin = 2, assume_isolated = 'martyna-tuckerman', lda_plus_u = True, conv_thr = 1.0e-9, mixing_beta = 0.7, diagonalization = 'david', mixing_fixed_ns = 500, mass = obj(Fe=58.69000), pseudos = ['Fe.pbe-nd-rrkjus.UPF'], elem = ['Fe','Fe'], pos = [[2.070000000, 0.000000000, 0.000000000], [0.000000000, 0.000000000, 0.000000000]], pos_specifier = 'angstrom', kgrid = np.array((1,1,1)), kshift = np.array((1,1,1)), ) pw.system.set({ 'celldm(1)' : 15, 'starting_magnetization(1)' : 0.9, 'hubbard_u(1)' : 3.1, 'starting_ns_eigenvalue(1,2,1)' : 0.0, 'starting_ns_eigenvalue(2,2,1)' : 0.0476060, 'starting_ns_eigenvalue(3,2,1)' : 0.0476060, 'starting_ns_eigenvalue(4,2,1)' : 0.9654373, 'starting_ns_eigenvalue(5,2,1)' : 0.9954307, }) generations[infile] = pw pw2 = compositions[infile] check_pw_same(pw,pw2,'generate','compose') if os.path.exists(write_path): os.remove(write_path) #end if pw.write(write_path) pw3 = PwscfInput(write_path) pw4 = reads[infile] check_pw_same(pw3,pw4,'generate','read') # based on sample_inputs/Fe_start_ns_eig.in # variant that uses direct pwscf array input pw = generate_pwscf_input( selector = 'generic', calculation = 'scf', restart_mode = 'from_scratch', wf_collect = True, outdir = './output', pseudo_dir = '../pseudo/', prefix = 'fe', etot_conv_thr = 1.0e-9, forc_conv_thr = 1.0e-6, tstress = True, tprnfor = True, ibrav = 1, nat = 2, ntyp = 1, ecutwfc = 100, ecutrho = 300, nbnd = 18, occupations = 'smearing', degauss = 0.0005, smearing = 'methfessel-paxton', nspin = 2, assume_isolated = 'martyna-tuckerman', lda_plus_u = True, conv_thr = 1.0e-9, mixing_beta = 0.7, diagonalization = 'david', mixing_fixed_ns = 500, mass = obj(Fe=58.69000), pseudos = ['Fe.pbe-nd-rrkjus.UPF'], elem = ['Fe','Fe'], pos = [[2.070000000, 0.000000000, 0.000000000], [0.000000000, 0.000000000, 0.000000000]], pos_specifier = 'angstrom', kgrid = np.array((1,1,1)), kshift = np.array((1,1,1)), starting_ns_eigenvalue = {(1,2,1) : 0.0, (2,2,1) : 0.0476060, (3,2,1) : 0.0476060, (4,2,1) : 0.9654373, (5,2,1) : 0.9954307,}, celldm = {1 : 15 }, starting_magnetization = {1 : 0.9}, hubbard_u = {1 : 3.1}, ) pwg = pw.copy() pwg.standardize_types() generations[infile] = pw pw2 = compositions[infile].copy() pw2.standardize_types() check_pw_same(pwg,pw2,'generate','compose') pw3 = reads[infile] check_pw_same(pwg,pw3,'generate','read') if os.path.exists(write_path): os.remove(write_path) #end if pw.write(write_path) pw4 = PwscfInput(write_path) check_pw_same(pwg,pw3,'generate','write') # restore logging function restore_nexus_log()