def test_radial_density(): import os tpath = testing.setup_unit_test_output_directory( 'qdens_radial', 'test_radial_density') exe = testing.executable_path('qdens-radial') qr_vmc_files_path = testing.unit_test_file_path( 'qdens_radial', 'diamond_twist/vmc') command = 'rsync -a {} {}'.format(qr_vmc_files_path, tpath) out, err, rc = execute(command) assert (rc == 0) vmc_path = os.path.join(tpath, 'vmc') vmc_infile = os.path.join(vmc_path, 'vmc.g000.twistnum_0.in.xml') assert (os.path.exists(vmc_infile)) vmc_infile = os.path.join(vmc_path, 'vmc.g001.twistnum_1.in.xml') assert (os.path.exists(vmc_infile)) vmc_infile = os.path.join(vmc_path, 'vmc.g002.twistnum_2.in.xml') assert (os.path.exists(vmc_infile)) vmc_infile = os.path.join(vmc_path, 'vmc.g003.twistnum_3.in.xml') assert (os.path.exists(vmc_infile)) files_bef = ''' vmc.avg.s000.SpinDensity_u+d+err.xsf vmc.avg.s000.SpinDensity_u+d-err.xsf vmc.avg.s000.SpinDensity_u+d.xsf vmc.g000.twistnum_0.in.xml vmc.g000.s000.scalar.dat vmc.g001.s000.scalar.dat vmc.g000.twistnum_0.in.g000.qmc vmc.g001.twistnum_1.in.g001.qmc vmc.g001.twistnum_1.in.xml vmc.g002.twistnum_2.in.xml vmc.g002.s000.scalar.dat vmc.g003.s000.scalar.dat vmc.g002.twistnum_2.in.g002.qmc vmc.g003.twistnum_3.in.g003.qmc vmc.g003.twistnum_3.in.xml vmc.out vmc.in vmc.info.xml '''.split() qr_dmc_files_path = testing.unit_test_file_path( 'qdens_radial', 'diamond_twist/dmc') command = 'rsync -a {} {}'.format(qr_dmc_files_path, tpath) out, err, rc = execute(command) assert (rc == 0) dmc_path = os.path.join(tpath, 'dmc') dmc_infile = os.path.join(dmc_path, 'dmc.g000.twistnum_0.in.xml') assert (os.path.exists(dmc_infile)) dmc_infile = os.path.join(dmc_path, 'dmc.g001.twistnum_1.in.xml') assert (os.path.exists(dmc_infile)) dmc_infile = os.path.join(dmc_path, 'dmc.g002.twistnum_2.in.xml') assert (os.path.exists(dmc_infile)) dmc_infile = os.path.join(dmc_path, 'dmc.g003.twistnum_3.in.xml') assert (os.path.exists(dmc_infile)) files_bef = ''' dmc.avg.s001.SpinDensity_u+d+err.xsf dmc.avg.s001.SpinDensity_u+d-err.xsf dmc.avg.s001.SpinDensity_u+d.xsf dmc.g001.s001.scalar.dat dmc.g000.s000.scalar.dat dmc.g000.s001.scalar.dat dmc.g000.twistnum_0.in.g000.qmc dmc.g001.twistnum_1.in.g001.qmc dmc.g000.twistnum_0.in.xml dmc.g001.twistnum_1.in.xml dmc.g001.s000.scalar.dat dmc.g002.s000.scalar.dat dmc.g002.s001.scalar.dat dmc.g003.s001.scalar.dat dmc.g002.twistnum_2.in.g002.qmc dmc.g003.twistnum_3.in.g003.qmc dmc.g002.twistnum_2.in.xml dmc.g003.twistnum_3.in.xml dmc.g003.s000.scalar.dat dmc.in dmc.out '''.split() assert (check_value_eq(set(os.listdir(dmc_path)), set(files_bef))) # VMC non-cumulative command = '{0} -s C -r 0.6 {1}/vmc.avg.s000.SpinDensity_u+d.xsf'.format( exe, vmc_path) out, err, rc = execute(command) # Assert that return code is 0 assert (rc == 0) # Assert that output is consistent with reference out_ref = ''' Norm: tot = 8.00000003 Non-Cumulative Value of C Species at Cutoff 0.6 is: 4.773264912162242 ''' assert (text_eq(out, out_ref)) # VMC cumulative command = '{0} -s C -r 0.6 -c {1}/vmc.avg.s000.SpinDensity_u+d.xsf'.format( exe, vmc_path) out, err, rc = execute(command) # Assert that return code is 0 assert (rc == 0) # Assert that output is consistent with reference out_ref = ''' Norm: tot = 8.00000003 Cumulative Value of C Species at Cutoff 0.6 is: 1.0684248641866259 ''' # DMC extrapolated non-cumulative command = '{0} -s C -r 0.6 --vmc={1}/vmc.avg.s000.SpinDensity_u+d.xsf {2}/dmc.avg.s001.SpinDensity_u+d.xsf'.format( exe, vmc_path, dmc_path) out, err, rc = execute(command) # Assert that return code is 0 assert (rc == 0) # Assert that output is consistent with reference out_ref = ''' Extrapolating from VMC and DMC densities... Norm: tot = 7.999999969999998 Non-Cumulative Value of C Species at Cutoff 0.6 is: 4.910093964664309 ''' assert (text_eq(out, out_ref)) # DMC extrapolated cumulative command = '{0} -s C -r 0.6 -c --vmc={1}/vmc.avg.s000.SpinDensity_u+d.xsf {2}/dmc.avg.s001.SpinDensity_u+d.xsf'.format( exe, vmc_path, dmc_path) out, err, rc = execute(command) # Assert that return code is 0 assert (rc == 0) # Assert that output is consistent with reference out_ref = ''' Extrapolating from VMC and DMC densities... Norm: tot = 7.999999969999998 Cumulative Value of C Species at Cutoff 0.6 is: 1.1078267486386275 ''' assert (text_eq(out, out_ref)) # DMC extrapolated cumulative with error bar command = '{0} -s C -r 0.6 -c -n 3 --seed=0 --vmc={1}/vmc.avg.s000.SpinDensity_u+d.xsf --vmcerr={1}/vmc.avg.s000.SpinDensity_u+d+err.xsf --dmcerr={2}/dmc.avg.s001.SpinDensity_u+d+err.xsf {2}/dmc.avg.s001.SpinDensity_u+d.xsf'.format( exe, vmc_path, dmc_path) out, err, rc = execute(command) # Assert that return code is 0 assert (rc == 0) # Assert that output is consistent with reference out_ref = ''' Extrapolating from VMC and DMC densities... Resampling to obtain error bar (NOTE: This can be slow)... Will compute 3 samples... sample: 0 sample: 1 sample: 2 Norm: tot = 7.999999969999998 Cumulative Value of C Species at Cutoff 0.6 is: 1.1078267486386275+/-0.0016066467833404942 ''' assert (text_eq(out, out_ref))
def test_incorporate_result(): import os import shutil from subprocess import Popen, PIPE from numpy import array from generic import NexusError, obj from nexus_base import nexus_core from test_vasp_simulation import setup_vasp_sim as get_vasp_sim from test_vasp_simulation import pseudo_inputs as vasp_pseudo_inputs from test_qmcpack_converter_simulations import get_pw2qmcpack_sim from test_qmcpack_converter_simulations import get_convert4qmc_sim from test_qmcpack_converter_simulations import get_pyscf_to_afqmc_sim pseudo_inputs = obj(vasp_pseudo_inputs) tpath = testing.setup_unit_test_output_directory( 'qmcpack_simulation', 'test_incorporate_result', **pseudo_inputs) nexus_core.runs = '' nexus_core.results = '' # incorporate vasp structure sim = get_qmcpack_sim(identifier='qmc_vasp_structure', tiling=(2, 2, 2)) vasp_struct = get_vasp_sim(tpath, identifier='vasp_structure', files=True) assert (sim.locdir.strip('/') == tpath.strip('/')) pc_file = 'diamond_POSCAR' cc_file = vasp_struct.identifier + '.CONTCAR' shutil.copy2(os.path.join(tpath, pc_file), os.path.join(tpath, cc_file)) result = vasp_struct.get_result('structure', None) ion0 = sim.input.get('ion0') c = ion0.groups.C cp0 = c.position[0].copy() s = result.structure.copy() s.change_units('B') rp0 = s.pos[0] zero = array([0, 0, 0], dtype=float) assert (value_eq(c.position[0], cp0, atol=1e-8)) c.position[0] += 0.1 assert (not value_eq(c.position[0], cp0, atol=1e-8)) assert (not value_eq(c.position[0], rp0, atol=1e-8)) sim.incorporate_result('structure', result, vasp_struct) ion0 = sim.input.get('ion0') c = ion0.groups.C assert (value_eq(c.position[0], rp0, atol=1e-8)) # incorporate pw2qmcpack orbitals sim = get_qmcpack_sim(identifier='qmc_p2q_orbitals') p2q_orb = get_pw2qmcpack_sim(identifier='p2q_orbitals') result = p2q_orb.get_result('orbitals', None) p2q_output_path = os.path.join(tpath, 'pwscf_output') if not os.path.exists(p2q_output_path): os.makedirs(p2q_output_path) #end if p2q_h5file = os.path.join(p2q_output_path, 'pwscf.pwscf.h5') f = open(p2q_h5file, 'w') f.write('') f.close() assert (os.path.exists(p2q_h5file)) spo = sim.input.get('bspline') assert (spo.href == 'MISSING.h5') sim.incorporate_result('orbitals', result, p2q_orb) assert (spo.href == 'pwscf_output/pwscf.pwscf.h5') # incorporate convert4qmc orbitals sim = get_qmcpack_sim(identifier='qmc_c4q_orbitals') c4q_orb = get_convert4qmc_sim(identifier='c4q_orbitals') result = c4q_orb.get_result('orbitals', None) wfn_file = os.path.join(tpath, 'c4q_orbitals.wfj.xml') wfn_file2 = os.path.join(tpath, 'c4q_orbitals.orbs.h5') input = sim.input.copy() dset = input.get('determinantset') dset.href = 'orbs.h5' qs = input.simulation.qmcsystem del input.simulation input.qmcsystem = qs input.write(wfn_file) assert (os.path.exists(wfn_file)) open(wfn_file2, 'w').write('fake') assert (os.path.exists(wfn_file2)) from qmcpack_input import QmcpackInput inp = QmcpackInput(wfn_file) dset = sim.input.get('determinantset') assert ('href' not in dset) sim.incorporate_result('orbitals', result, c4q_orb) dset = sim.input.get('determinantset') assert (dset.href == 'c4q_orbitals.orbs.h5') # incorporate qmcpack jastrow sim = get_qmcpack_sim(identifier='qmc_jastrow') qa_files_path = testing.unit_test_file_path('qmcpack_analyzer', 'diamond_gamma/opt') command = 'rsync -a {} {}'.format(qa_files_path, tpath) process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, close_fds=True) out, err = process.communicate() opt_path = os.path.join(tpath, 'opt') opt_infile = os.path.join(opt_path, 'opt.in.xml') assert (os.path.exists(opt_infile)) opt_file = os.path.join(opt_path, 'opt.s004.opt.xml') assert (os.path.exists(opt_file)) result = obj(opt_file=opt_file) sim.incorporate_result('jastrow', result, sim) j = sim.input.get('jastrow') j_text = j.write().replace('"', ' " ') j_text_ref = ''' <jastrow type="Two-Body" name="J2" function="bspline" print="yes"> <correlation speciesA="u" speciesB="u" size="8" rcut="2.3851851232"> <coefficients id="uu" type="Array"> 0.2576630369 0.1796686015 0.1326653657 0.09407180823 0.06267013118 0.03899100023 0.02070235604 0.009229775746 </coefficients> </correlation> <correlation speciesA="u" speciesB="d" size="8" rcut="2.3851851232"> <coefficients id="ud" type="Array"> 0.4385891515 0.3212399072 0.2275448261 0.1558506324 0.1009589176 0.06108433554 0.03154274436 0.01389485975 </coefficients> </correlation> </jastrow> '''.replace('"', ' " ') assert (text_eq(j_text, j_text_ref)) # incorporate qmcpack wavefunction sim = get_qmcpack_sim(identifier='qmc_wavefunction') sim.incorporate_result('wavefunction', result, sim) j = sim.input.get('jastrow') j_text = j.write().replace('"', ' " ') assert (text_eq(j_text, j_text_ref)) # incorporate qmcpack wavefunction afqmc sim = get_qmcpack_sim(type='afqmc', identifier='qmc_wf_afqmc') p2a_wf = get_pyscf_to_afqmc_sim(identifier='p2a_wavefunction') result = p2a_wf.get_result('wavefunction', None) del result.xml wfn = sim.input.get('wavefunction') ham = sim.input.get('hamiltonian') assert (wfn.filename == 'MISSING.h5') assert (ham.filename == 'MISSING.h5') sim.incorporate_result('wavefunction', result, p2a_wf) assert (wfn.filename == 'p2a_wavefunction.afqmc.h5') assert (ham.filename == 'p2a_wavefunction.afqmc.h5') clear_all_sims() restore_nexus()
def test_read(): import os import numpy as np import h5py from hdfreader import read_hdf ds = 'string value' di = 100 df = np.pi das = np.array(tuple('abcdefghijklmnopqrstuvwxyz'), dtype=bytes) dai = np.arange(20, dtype=np.int64) daf = 0.1 * np.arange(20, dtype=np.float64) path = testing.setup_unit_test_output_directory( 'hdfreader', 'test_read') def add_datasets(g): g.create_dataset('sdata', data=das) g.create_dataset('idata', data=dai) g.create_dataset('fdata', data=daf) #end def add_datasets def add_attrs(g): g.attrs['sval'] = ds g.attrs['ival'] = di g.attrs['fval'] = df #end def add_attrs def add_group(g, label=''): g = g.create_group('group' + str(label)) add_attrs(g) add_datasets(g) return g #end def add_group testfile = os.path.join(path, 'test.h5') f = h5py.File(testfile, 'w') add_datasets(f) g1 = add_group(f, 1) g2 = add_group(f, 2) g11 = add_group(g1, 1) g12 = add_group(g1, 2) g21 = add_group(g2, 1) g22 = add_group(g2, 2) f.close() def check_datasets(g): assert (value_eq(g.sdata, das)) assert (value_eq(g.idata, dai)) assert (value_eq(g.fdata, daf)) #end def check_datasets def check_groups(g): assert ('group1' in g) assert ('group2' in g) check_datasets(g.group1) check_datasets(g.group2) #end def check_groups h = read_hdf(testfile) check_datasets(h) check_groups(h) check_groups(h.group1) check_groups(h.group2)
def test_vmc_dmc_analysis(): import os from generic import obj from qmcpack_analyzer import QmcpackAnalyzer tpath = testing.setup_unit_test_output_directory( test='qmcpack_analyzer', subtest='test_vmc_dmc_analysis', file_sets=['diamond_gamma'], ) # test load of vmc data infile = os.path.join(tpath, 'diamond_gamma/vmc/vmc.in.xml') qa = QmcpackAnalyzer(infile) qa_keys = 'info vmc qmc wavefunction'.split() assert (set(qa.keys()) == set(qa_keys)) qmc = qa.qmc qmc_keys = [0] assert (set(qmc.keys()) == set(qmc_keys)) vmc = qa.qmc[0] vmc_keys = 'info scalars scalars_hdf'.split() assert (len(set(vmc.keys()) - set(vmc_keys)) == 0) assert ('scalars' in vmc) scalars = vmc.scalars scalars_keys = 'info method_info data'.split() assert (set(scalars.keys()) == set(scalars_keys)) data = scalars.data data_keys = ''' AcceptRatio BlockCPU BlockWeight ElecElec IonIon Kinetic LocalECP LocalEnergy LocalEnergy_sq LocalPotential MPC NonLocalECP '''.split() assert (set(data.keys()) == set(data_keys)) # test analysis of vmc data qa = QmcpackAnalyzer(infile, analyze=True, equilibration=10) scalars = qa.qmc[0].scalars skeys = scalars_keys + data_keys + ['LocalEnergyVariance'] assert (set(scalars.keys()) == set(skeys)) del scalars.data del scalars.info del scalars.method_info scalars_ref = obj( AcceptRatio=obj( error=0.00039521879435689295, kappa=1.0759731314133185, mean=0.7692893518516666, sample_variance=1.3065205976562954e-05, ), BlockCPU=obj( error=0.00021580706746995528, kappa=17.761816682736388, mean=0.035813258793955555, sample_variance=2.3598611606955374e-07, ), BlockWeight=obj( error=0.0, kappa=1.0, mean=600.0, sample_variance=0.0, ), ElecElec=obj( error=0.006371421551195983, kappa=1.139934660946538, mean=-2.7418612341177777, sample_variance=0.003205053111939163, ), IonIon=obj( error=3.744889033148481e-16, kappa=1.0, mean=-12.775667474000004, sample_variance=1.262177448353619e-29, ), Kinetic=obj( error=0.023892472166667816, kappa=1.2234867804809575, mean=11.078538966677776, sample_variance=0.04199188841333729, ), LocalECP=obj( error=0.028248848774549792, kappa=1.3238620182010674, mean=-6.548159166556667, sample_variance=0.054250193864959544, ), LocalEnergy=obj( error=0.0036722831372396907, kappa=1.9941956906300935, mean=-10.458057094266668, sample_variance=0.0006086211675753148, ), LocalEnergyVariance=obj( error=0.010209447771536196, kappa=1.0, mean=0.39878166800218146, sample_variance=0.009380954141975286, ), LocalEnergy_sq=obj( error=0.07644640401544833, kappa=1.9594807148999176, mean=109.77034847611111, sample_variance=0.26842047376171707, ), LocalPotential=obj( error=0.025040457075256945, kappa=1.2285412284015842, mean=-21.53659606088889, sample_variance=0.045934318559111634, ), MPC=obj( error=0.006576052786612818, kappa=1.094304580426513, mean=-2.4782162843888895, sample_variance=0.0035565987681342825, ), NonLocalECP=obj( error=0.009208836158892106, kappa=1.3807747631543386, mean=0.5290918141037778, sample_variance=0.005527505216479378, ), ) assert (object_eq(scalars.to_obj(), scalars_ref)) # test analysis of dmc data infile = os.path.join(tpath, 'diamond_gamma/dmc/dmc.in.xml') qa = QmcpackAnalyzer(infile, analyze=True, equilibration=5) qmc = qa.qmc qmc_keys = [0, 1, 2, 3] assert (set(qmc.keys()) == set(qmc_keys)) le = obj() for n in qmc_keys: le[n] = qmc[n].scalars.LocalEnergy.mean #end for le_ref = obj({ 0: -10.4891061838, 1: -10.531650024088888, 2: -10.530189168355555, 3: -10.528843362733333, }) assert (object_eq(le, le_ref))
def test_get_result(): import os from subprocess import Popen, PIPE from generic import NexusError, obj from nexus_base import nexus_core from qmcpack_analyzer import QmcpackAnalyzer tpath = testing.setup_unit_test_output_directory('qmcpack_simulation', 'test_get_result', divert=True) nexus_core.runs = '' nexus_core.results = '' sim = get_qmcpack_sim() assert (sim.locdir.rstrip('/') == tpath.rstrip('/')) try: sim.get_result('unknown', None) raise FailedTest except NexusError: None except FailedTest: failed() except Exception as e: failed(str(e)) #end try result = sim.get_result('cuspcorr', None) result_ref = obj( updet_cusps='updet.cuspInfo.xml', spo_dn_cusps='qmcpack.spo-dn.cuspInfo.xml', spo_up_cusps='qmcpack.spo-up.cuspInfo.xml', dndet_cusps='downdet.cuspInfo.xml', ) assert (set(result.keys()) == set(result_ref.keys())) for k, v in result.items(): assert (v.replace(tpath, '').lstrip('/') == result_ref[k]) #end for qa_files_path = testing.unit_test_file_path('qmcpack_analyzer', 'diamond_gamma/opt') command = 'rsync -a {} {}'.format(qa_files_path, tpath) process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, close_fds=True) out, err = process.communicate() opt_path = os.path.join(tpath, 'opt') opt_infile = os.path.join(opt_path, 'opt.in.xml') assert (os.path.exists(opt_infile)) qa = QmcpackAnalyzer(opt_infile, analyze=True, equilibration=5) assert (qa.results.optimization.optimal_file == 'opt.s003.opt.xml') sim.create_directories() qa.save(os.path.join(sim.imresdir, sim.analyzer_image)) result = sim.get_result('jastrow', None) result_ref = obj(opt_file='opt.s003.opt.xml', ) assert (set(result.keys()) == set(result_ref.keys())) for k, v in result.items(): assert (v.replace(tpath, '').lstrip('/') == result_ref[k]) #end for clear_all_sims() restore_nexus()
def test_optimization_analysis(): import os from numpy import array from generic import obj from qmcpack_analyzer import QmcpackAnalyzer tpath = testing.setup_unit_test_output_directory( test='qmcpack_analyzer', subtest='test_optimization_analysis', file_sets=['diamond_gamma'], ) divert_nexus_log() infile = os.path.join(tpath, 'diamond_gamma/opt/opt.in.xml') qa = QmcpackAnalyzer(infile, analyze=True, equilibration=5) qa_keys = 'info wavefunction opt qmc results'.split() assert (set(qa.keys()) == set(qa_keys)) qmc = qa.qmc qmc_keys = range(6) assert (set(qmc.keys()) == set(qmc_keys)) le_opt = obj() for n in qmc_keys: le_opt[n] = qmc[n].scalars.LocalEnergy.mean #end for le_opt_ref = obj({ 0: -10.449225495355556, 1: -10.454263886688889, 2: -10.459916961266668, 3: -10.4583030738, 4: -10.462984807955555, 5: -10.460860545622223, }) assert (object_eq(le_opt, le_opt_ref)) results = qa.results results_keys = ['optimization'] assert (set(results.keys()) == set(results_keys)) opt = results.optimization opt_keys = ''' all_complete any_complete energy energy_error energy_weight failed info optimal_file optimal_series optimal_wavefunction optimize opts series unstable variance variance_error variance_weight '''.split() assert (set(opt.keys()) == set(opt_keys)) from qmcpack_input import wavefunction assert (isinstance(opt.optimal_wavefunction, wavefunction)) opt_wf = opt.optimal_wavefunction opt_wf_text = opt_wf.write() opt_wf_text_ref = ''' <wavefunction name="psi0" target="e"> <sposet_builder type="bspline" href="../scf/pwscf_output/pwscf.pwscf.h5" tilematrix="1 0 0 0 1 0 0 0 1" twistnum="0" source="ion0" version="0.1" meshfactor="1.0" precision="float" truncate="no"> <sposet type="bspline" name="spo_ud" size="4" spindataset="0"> </sposet> </sposet_builder> <determinantset> <slaterdeterminant> <determinant id="updet" group="u" sposet="spo_ud" size="4"/> <determinant id="downdet" group="d" sposet="spo_ud" size="4"/> </slaterdeterminant> </determinantset> <jastrow type="Two-Body" name="J2" function="bspline" print="yes"> <correlation speciesA="u" speciesB="u" size="8" rcut="2.3851851232"> <coefficients id="uu" type="Array"> 0.2576630369 0.1796686015 0.1326653657 0.09407180823 0.06267013118 0.03899100023 0.02070235604 0.009229775746 </coefficients> </correlation> <correlation speciesA="u" speciesB="d" size="8" rcut="2.3851851232"> <coefficients id="ud" type="Array"> 0.4385891515 0.3212399072 0.2275448261 0.1558506324 0.1009589176 0.06108433554 0.03154274436 0.01389485975 </coefficients> </correlation> </jastrow> </wavefunction> ''' opt_wf_text_ref = opt_wf_text_ref.replace('"', ' " ') opt_wf_text = opt_wf_text.replace('"', ' " ') assert (text_eq(opt_wf_text, opt_wf_text_ref)) del opt.info del opt.opts del opt.optimal_wavefunction opt_ref = obj( all_complete=True, any_complete=True, energy=array([ -10.45426389, -10.45991696, -10.45830307, -10.46298481, -10.46086055 ], dtype=float), energy_error=array( [0.00320561, 0.00271802, 0.00298106, 0.00561322, 0.00375811], dtype=float), energy_weight=None, failed=False, optimal_file='opt.s003.opt.xml', optimal_series=3, optimize=(1.0, 0.0), series=array([1, 2, 3, 4, 5], dtype=int), unstable=False, variance=array( [0.40278743, 0.39865602, 0.38110459, 0.38927957, 0.39354343], dtype=float), variance_error=array( [0.01716415, 0.00934316, 0.00529809, 0.01204068, 0.00913372], dtype=float), variance_weight=None, ) assert (object_eq(opt.to_obj(), opt_ref, atol=1e-8)) restore_nexus_log()
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()
def test_analyze(): import os from numpy import array, ndarray from generic import obj from gamess_analyzer import GamessAnalyzer tpath = testing.setup_unit_test_output_directory( test='gamess_analyzer', subtest='test_analyze', file_sets=['gms.inp', 'gms.out'], ) outpath = os.path.join(tpath, 'gms.inp') # no analysis ga = GamessAnalyzer(outpath) del ga.info.input del ga.info.path ga_ref = obj(info=obj( exit=False, initialized=True, prefix='gms', files=obj( aabb41='gms.F41', aoints='gms.F08', bbaa42='gms.F42', bbbb43='gms.F43', casints='gms.F13', ccdiis='gms.F71', ccints='gms.F72', ccquads='gms.F78', ccrest='gms.F70', cct1amp='gms.F73', cct2amp='gms.F74', cct3amp='gms.F75', ccve='gms.F77', ccvm='gms.F76', ciints='gms.F14', civectr='gms.F12', csfsave='gms.F17', dafl30='gms.F30', dasort='gms.F20', dcphfh2='gms.F67', dftgrid='gms.F22', dftints='gms.F21', dictnry='gms.F10', drtfile='gms.F11', efmof='gms.F103', efmoi='gms.F102', efpind='gms.F25', eomdg12='gms.F89', eomhc1='gms.F83', eomhc2='gms.F84', eomhhhh='gms.F85', eomhl1='gms.F98', eomhl2='gms.F99', eomlvec='gms.F97', eompppp='gms.F86', eomramp='gms.F87', eomrtmp='gms.F88', eomstar='gms.F80', eomvec1='gms.F81', eomvec2='gms.F82', eomvl1='gms.F95', eomvl2='gms.F96', fockder='gms.F18', hessian='gms.F38', input='gms.inp', jkfile='gms.F23', mcqd50='gms.F50', mcqd51='gms.F51', mcqd52='gms.F52', mcqd53='gms.F53', mcqd54='gms.F54', mcqd55='gms.F55', mcqd56='gms.F56', mcqd57='gms.F57', mcqd58='gms.F58', mcqd59='gms.F59', mcqd60='gms.F60', mcqd61='gms.F61', mcqd62='gms.F62', mcqd63='gms.F63', mcqd64='gms.F64', mltpl='gms.F28', mltplt='gms.F29', mmciitr='gms.F94', mmcivc1='gms.F93', mmcivec='gms.F92', mmhpp='gms.F91', mmpp='gms.F90', moints='gms.F09', nmrint1='gms.F61', ordint='gms.F24', output='gms.out', pcmdata='gms.F26', pcmints='gms.F27', punch='gms.F07', quadsvo='gms.F79', remd='gms.F44', restart='gms.F35', soccdat='gms.F40', traject='gms.F04', work15='gms.F15', work16='gms.F16', work19='gms.F19', ), )) assert (object_eq(ga.to_obj(), ga_ref)) # full analysis ga = GamessAnalyzer(outpath, analyze=True) del ga.info.input del ga.info.path del ga.info.files ga_ref = obj( ao_populations=obj( lowdin=array([ 8.3070e-02, 2.5080e-02, 5.2000e-04, 2.3000e-04, 7.3660e-02, 0.0000e+00, 0.0000e+00, 1.3479e-01, 0.0000e+00, 0.0000e+00, 6.2610e-02, 0.0000e+00, 0.0000e+00, 2.1910e-02, 3.4700e-02, 3.4700e-02, 1.2332e-01, 0.0000e+00, 0.0000e+00, 0.0000e+00, 2.3050e-02, 2.3050e-02, 1.2369e-01, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 9.8720e-02, 0.0000e+00, 1.6890e-02, 0.0000e+00, 1.6890e-02, 0.0000e+00, 0.0000e+00, 0.0000e+00, 3.0345e-01, 1.7130e-02, 7.4000e-04, 7.0500e-03, 2.4783e-01, 0.0000e+00, 0.0000e+00, 5.0000e-05, 0.0000e+00, 0.0000e+00, 1.1000e-03, 0.0000e+00, 0.0000e+00, 4.7200e-03, 6.1080e-02, 6.1080e-02, 6.1380e-02, 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.0230e-01, 1.0230e-01, 1.3176e-01, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 7.6000e-04, 0.0000e+00, 2.1000e-04, 0.0000e+00, 2.1000e-04, 0.0000e+00, 0.0000e+00, 0.0000e+00 ], dtype=float), lowdin_shell=array([ 8.3070e-02, 2.5080e-02, 5.2000e-04, 2.3000e-04, 7.3660e-02, 3.0345e-01, 1.7130e-02, 7.4000e-04, 7.0500e-03, 2.4783e-01, 1.3479e-01, 6.2610e-02, 2.1910e-02, 5.0000e-05, 1.1000e-03, 4.7200e-03, 1.9272e-01, 1.6979e-01, 1.8354e-01, 3.3636e-01, 1.3250e-01, 1.1800e-03 ], dtype=float), mulliken=array([ 7.4225e-01, 1.1141e-01, -1.0500e-03, -4.9000e-04, -4.5679e-01, 0.0000e+00, 0.0000e+00, 4.6670e-01, 0.0000e+00, 0.0000e+00, -2.0338e-01, 0.0000e+00, 0.0000e+00, 2.5550e-02, 2.3860e-02, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.4390e-02, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 6.2800e-03, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.5046e+00, 2.9270e-02, 1.8600e-03, 2.0000e-05, -2.6496e-01, 0.0000e+00, 0.0000e+00, 3.0000e-05, 0.0000e+00, 0.0000e+00, 8.3000e-04, 0.0000e+00, 0.0000e+00, -4.2000e-04, -0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 6.0000e-05, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, -0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00 ], dtype=float), mulliken_shell=array([ 7.4225e-01, 1.1141e-01, -1.0500e-03, -4.9000e-04, -4.5679e-01, 1.5046e+00, 2.9270e-02, 1.8600e-03, 2.0000e-05, -2.6496e-01, 4.6670e-01, -2.0338e-01, 2.5550e-02, 3.0000e-05, 8.3000e-04, -4.2000e-04, 2.3860e-02, 1.4390e-02, 0.0000e+00, 6.0000e-05, 6.2800e-03, 0.0000e+00 ], dtype=float), basis=obj( angular=array([ 'S', 'S', 'S', 'S', 'S', 'X', 'Y', 'Z', 'X', 'Y', 'Z', 'X', 'Y', 'Z', 'XX', 'YY', 'ZZ', 'XY', 'XZ', 'YZ', 'XX', 'YY', 'ZZ', 'XY', 'XZ', 'YZ', 'XXX', 'YYY', 'ZZZ', 'XXY', 'XXZ', 'YYX', 'YYZ', 'ZZX', 'ZZY', 'XYZ', 'S', 'S', 'S', 'S', 'S', 'X', 'Y', 'Z', 'X', 'Y', 'Z', 'X', 'Y', 'Z', 'XX', 'YY', 'ZZ', 'XY', 'XZ', 'YZ', 'XX', 'YY', 'ZZ', 'XY', 'XZ', 'YZ', 'XXX', 'YYY', 'ZZZ', 'XXY', 'XXZ', 'YYX', 'YYZ', 'ZZX', 'ZZY', 'XYZ' ]), d=array([ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61 ], dtype=int), element=array([ 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'Li', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'H' ]), f=array([ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71 ], dtype=int), g=array([], dtype=int), p=array([ 5, 6, 7, 8, 9, 10, 11, 12, 13, 41, 42, 43, 44, 45, 46, 47, 48, 49 ], dtype=int), s=array([0, 1, 2, 3, 4, 36, 37, 38, 39, 40], dtype=int), spec_index=array([ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ], dtype=int), ), lowdin_angular=obj( d=0.88241, f=0.13368, g=0.0, p=0.22518, s=0.75876, ), mulliken_angular=obj( d=0.03831, f=0.00628, g=0.0, p=0.28931, s=1.666119999999999, ), shell=obj( d=array([16, 17, 18, 19], dtype=int), f=array([20, 21], dtype=int), g=array([], dtype=int), p=array([10, 11, 12, 13, 14, 15], dtype=int), s=array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int), ), ), counts=obj( cao=72, mos=62, shells=22, ), energy=obj( electron_electron_potential=0.4814819907, nuclear_repulsion=0.3317933721, nucleus_electron_potential=-2.199450924, nucleus_nucleus_potential=0.3317933721, one_electron=-1.5640017754, total=-0.7507264125, total_kinetic=0.6354491487, total_potential=-1.3861755612, two_electron=0.4814819907, ), info=obj( exit=False, initialized=True, prefix='gms', ), ) assert (object_eq(ga.to_obj(), ga_ref))
def test_pseudopotential_classes(): import os import numpy as np from pseudopotential import SemilocalPP from pseudopotential import GaussianPP from pseudopotential import QmcpackPP from pseudopotential import CasinoPP tpath = testing.setup_unit_test_output_directory( 'pseudopotential', 'test_pseudopotential_classes') files = get_files() # empty initialization SemilocalPP() GaussianPP() QmcpackPP() CasinoPP() qpp = QmcpackPP(files['C.BFD.xml']) # SemilocalPP attributes/methods assert (qpp.name is None) assert (qpp.rcut is None) assert (qpp.lmax == 1) assert (qpp.local == 'p') assert (qpp.has_component('s')) assert (qpp.has_component('p')) assert (isinstance(qpp.get_component('s'), np.ndarray)) assert (isinstance(qpp.get_component('p'), np.ndarray)) assert (qpp.has_local()) assert (qpp.has_nonlocal()) assert (not qpp.has_L2()) vnl = qpp.get_nonlocal() rc = qpp.find_rcut() assert (value_eq(rc, 1.705, atol=1e-3)) # below follows by virtue of being numeric qpp.assert_numeric('some location') vcomp = qpp.components vloc = qpp.evaluate_local(rpow=1) assert (value_eq(vloc, vcomp.p)) vnonloc = qpp.evaluate_nonlocal(l='s', rpow=1) assert (value_eq(vnonloc, vcomp.s)) vs = qpp.evaluate_channel(l='s', rpow=1) assert (value_eq(vs, vcomp.s + vcomp.p)) vp = qpp.evaluate_channel(l='p', rpow=1) assert (value_eq(vp, vcomp.p)) r, vsn = qpp.numeric_channel(l='s', rpow=1) r, vpn = qpp.numeric_channel(l='p', rpow=1) assert (value_eq(r, qpp.r)) assert (value_eq(vsn, vs)) assert (value_eq(vpn, vp)) # QmcpackPP attributes/methods assert (qpp.numeric) assert (qpp.Zcore == 2) assert (qpp.Zval == 4) assert (qpp.core == 'He') assert (qpp.element == 'C') assert (value_eq(float(qpp.rmin), 0.)) assert (value_eq(qpp.rmax, 10.)) assert (value_eq(qpp.r.min(), 0.)) assert (value_eq(qpp.r.max(), 10.)) assert (value_eq(qpp.v_at_zero('s'), 22.551641791033372)) assert (value_eq(qpp.v_at_zero('p'), -19.175372435022126)) qpp_fake = qpp.copy() r = np.linspace(0, 10, 6) vloc = 0 * r + qpp.Zval vnl = 0 * r qpp_fake.r = r qpp_fake.components.s = vnl qpp_fake.components.p = vloc qtext_ref = '''<?xml version="1.0" encoding="UTF-8"?> <pseudo version="0.5"> <header symbol="C" atomic-number="6" zval="4" relativistic="unknown" polarized="unknown" creator="Nexus" flavor="unknown" core-corrections="unknown" xc-functional-type="unknown" xc-functional-parametrization="unknown"/> <grid type="linear" units="bohr" ri="0.0" rf="10.0" npts="6"/> <semilocal units="hartree" format="r*V" npots-down="2" npots-up="0" l-local="1"> <vps principal-n="0" l="s" spin="-1" cutoff="10.0" occupation="unknown"> <radfunc> <grid type="linear" units="bohr" ri="0.0" rf="10.0" npts="6"/> <data> 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 </data> </radfunc> </vps> <vps principal-n="0" l="p" spin="-1" cutoff="10.0" occupation="unknown"> <radfunc> <grid type="linear" units="bohr" ri="0.0" rf="10.0" npts="6"/> <data> 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 </data> </radfunc> </vps> </semilocal> </pseudo>''' qtext = qpp_fake.write_qmcpack() assert (qtext.strip() == qtext_ref.strip()) ctext_ref = '''C pseudopotential converted by Nexus Atomic number and pseudo-charge 6 4.0 Energy units (rydberg/hartree/ev): hartree Angular momentum of local component (0=s,1=p,2=d..) 1 NLRULE override (1) VMC/DMC (2) config gen (0 ==> input/default value) 0 0 Number of grid points 6 R(i) in atomic units 0.00000000000000e+00 2.00000000000000e+00 4.00000000000000e+00 6.00000000000000e+00 8.00000000000000e+00 1.00000000000000e+01 r*potential (L=0) in Ha 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 r*potential (L=1) in Ha 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00 4.00000000000000e+00''' ctext = qpp_fake.write_casino() assert (ctext.strip() == ctext_ref.strip()) # tests for GaussianPP gpp = GaussianPP(files['C.BFD.gms'], format='gamess') assert (gpp.Zcore == 2) assert (gpp.Zval == 4) assert (gpp.core == 'He') assert (gpp.element == 'C') assert (gpp.lmax == 1) assert (gpp.local == 'p') assert (gpp.name is None) assert (value_eq(gpp.rcut, 1.7053, atol=1e-3)) assert (len(gpp.basis) == 20) nterms_ref = [9, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] nterms = [] for n in range(len(gpp.basis)): nterms.append(len(gpp.basis[n].terms)) #end for assert (nterms == nterms_ref) assert (value_eq(gpp.basis[5].terms[4].coeff, 0.289868)) assert (len(gpp.components.s) == 1) assert (len(gpp.components.p) == 3) assert (value_eq(gpp.components.p[1].expon, 4.48361888)) # check cross-format write/read gamess_file = os.path.join(tpath, 'C.BFD.gamess') gpp.write(gamess_file, format='gamess') gaussian_file = os.path.join(tpath, 'C.BFD.gaussian') gpp.write(gaussian_file, format='gaussian') qmcpack_file = os.path.join(tpath, 'C.BFD.qmcpack') gpp.write(qmcpack_file, format='qmcpack') casino_file = os.path.join(tpath, 'C.BFD.casino') gpp.write(casino_file, format='casino') gpp_gamess = GaussianPP(gamess_file, format='gamess') assert (object_eq(gpp_gamess, gpp)) gpp_gaussian = GaussianPP(gaussian_file, format='gaussian') assert (object_eq(gpp_gaussian, gpp)) qpp_qmcpack = QmcpackPP(qmcpack_file) assert (object_eq(qpp_qmcpack, qpp, int_as_float=True, atol=1e-12)) # tests for CasinoPP cpp = CasinoPP(casino_file) qo = qpp.to_obj() co = cpp.to_obj() del qo.rmin del qo.rmax assert (object_eq(co, qo, atol=1e-12)) qmcpack_from_casino_file = os.path.join(tpath, 'C.BFD.qmcpack_from_casino') cpp.write_qmcpack(qmcpack_from_casino_file) qpp_casino = QmcpackPP(qmcpack_from_casino_file) assert (object_eq(qpp_casino, qpp, int_as_float=True, atol=1e-12))
def test_sim(): import os from nexus_base import nexus_core from test_simulation_module import get_sim tpath = testing.setup_unit_test_output_directory('nxs_sim', 'test_sim', divert=True) nexus_core.runs = '' nexus_core.results = '' exe = testing.executable_path('nxs-sim') sim = get_sim() sim.create_directories() sim.save_image() simp_path = os.path.join(tpath, sim.imlocdir, 'sim.p') assert (os.path.isfile(simp_path)) # initial simulation state command = '{} show {}'.format(exe, simp_path) out, err, rc = execute(command) out_ref = ''' {} setup 0 sent_files 0 submitted 0 finished 0 failed 0 got_output 0 analyzed 0 '''.format(simp_path) assert (text_eq(out, out_ref)) # final simulation state command = '{} complete {}'.format(exe, simp_path) out, err, rc = execute(command) command = '{} show {}'.format(exe, simp_path) out, err, rc = execute(command) out_ref = ''' {} setup 1 sent_files 1 submitted 1 finished 1 failed 0 got_output 1 analyzed 1 '''.format(simp_path) assert (text_eq(out, out_ref)) # intermediate simulation state 1 command = '{} reset {}'.format(exe, simp_path) out, err, rc = execute(command) command = '{} set setup sent_files submitted {}'.format(exe, simp_path) out, err, rc = execute(command) command = '{} show {}'.format(exe, simp_path) out, err, rc = execute(command) out_ref = ''' {} setup 1 sent_files 1 submitted 1 finished 0 failed 0 got_output 0 analyzed 0 '''.format(simp_path) # intermediate simulation state 2 command = '{} complete {}'.format(exe, simp_path) out, err, rc = execute(command) command = '{} unset got_output analyzed {}'.format(exe, simp_path) out, err, rc = execute(command) command = '{} show {}'.format(exe, simp_path) out, err, rc = execute(command) out_ref = ''' {} setup 1 sent_files 1 submitted 1 finished 1 failed 0 got_output 0 analyzed 0 '''.format(simp_path) assert (text_eq(out, out_ref)) clear_all_sims() restore_nexus()