コード例 #1
0
ファイル: test_qmca.py プロジェクト: PDoakORNL/qmcpack
def test_multiple_directories():
    exe = get_exe()

    enter('multi')

    command = sys.executable + " {} -e 5 -q ev --fp=16.8f */*scalar*".format(
        exe)
    out, err, rc = execute(command)

    out_ref = '''
                  LocalEnergy                 Variance                   ratio 
dmc/dmc series 0 -10.48910618 +/- 0.00714379  0.45789123 +/- 0.04510618  0.0437 
dmc/dmc series 1 -10.53165002 +/- 0.00153762  0.38502189 +/- 0.00158532  0.0366 
dmc/dmc series 2 -10.53018917 +/- 0.00106340  0.38161141 +/- 0.00111391  0.0362 
dmc/dmc series 3 -10.52884336 +/- 0.00135513  0.38568155 +/- 0.00151082  0.0366 
 
opt/opt series 0 -10.44922550 +/- 0.00475437  0.60256216 +/- 0.01476264  0.0577 
opt/opt series 1 -10.45426389 +/- 0.00320561  0.40278743 +/- 0.01716415  0.0385 
opt/opt series 2 -10.45991696 +/- 0.00271802  0.39865602 +/- 0.00934316  0.0381 
opt/opt series 3 -10.45830307 +/- 0.00298106  0.38110459 +/- 0.00529809  0.0364 
opt/opt series 4 -10.46298481 +/- 0.00561322  0.38927957 +/- 0.01204068  0.0372 
opt/opt series 5 -10.46086055 +/- 0.00375811  0.39354343 +/- 0.00913372  0.0376 

vmc/vmc series 0 -10.45972798 +/- 0.00380164  0.39708591 +/- 0.00971200  0.0380
        '''

    assert (text_eq(out, out_ref))

    leave()
コード例 #2
0
ファイル: test_qmca.py プロジェクト: PDoakORNL/qmcpack
def test_all_quantities():
    exe = get_exe()

    enter('vmc')

    command = sys.executable + " {} -e 5 --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
        vmc  series 0 
          LocalEnergy           =      -10.45972798 +/-       0.00380164 
          Variance              =        0.39708591 +/-       0.00971200 
          Kinetic               =       11.08225203 +/-       0.02281909 
          LocalPotential        =      -21.54198001 +/-       0.02390850 
          ElecElec              =       -2.73960796 +/-       0.00627045 
          LocalECP              =       -6.55900348 +/-       0.02845221 
          NonLocalECP           =        0.53229890 +/-       0.00924772 
          IonIon                =      -12.77566747 +/-       0.00000000 
          LocalEnergy_sq        =      109.80363374 +/-       0.07821849 
          MPC                   =       -2.47615080 +/-       0.00644218 
          BlockWeight           =      600.00000000 +/-       0.00000000 
          BlockCPU              =        0.03578981 +/-       0.00022222 
          AcceptRatio           =        0.76940789 +/-       0.00038843 
          Efficiency            =   122102.67468280 +/-       0.00000000 
          TotalTime             =        3.40003187 +/-       0.00000000 
          TotalSamples          =    57000.00000000 +/-       0.00000000 
          -------------------------------------------------------------- 
          CorrectedEnergy       =      -10.19627082 +/-       0.00469500 
        '''

    assert (text_eq(out, out_ref))

    leave()
コード例 #3
0
ファイル: test_qmca.py プロジェクト: zenandrea/qmcpack
def test_unit_conversion():
    exe = get_exe()

    enter('vmc')

    command = '{} -e 5 -q e -u eV --fp=16.8f *scalar*'.format(exe)
    out, err, rc = execute(command)

    out_ref = '''
        vmc  series 0  LocalEnergy  =  -284.62368087 +/- 0.10344802
        '''

    assert (text_eq(out, out_ref))

    leave()
コード例 #4
0
ファイル: test_qmca.py プロジェクト: zenandrea/qmcpack
def test_weighted_twist_average():
    exe = get_exe()

    enter('vmc_twist')

    command = "{} -a -w '1 3 3 1' -e 5 -q ev --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
              LocalEnergy                 Variance                   ratio 
avg series 0 -11.44375840 +/- 0.00292164  0.44863011 +/- 0.00502859  0.0392 
        '''

    assert (text_eq(out, out_ref))

    leave()
コード例 #5
0
ファイル: test_qmca.py プロジェクト: zenandrea/qmcpack
def test_twist_average():
    exe = get_exe()

    enter('vmc_twist')

    command = "{} -a -e 5 -q ev --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
              LocalEnergy                 Variance                   ratio 
avg series 0 -11.34367335 +/- 0.00257603  0.57340688 +/- 0.00442552  0.0505 
        '''

    assert (text_eq(out, out_ref))

    leave()
コード例 #6
0
ファイル: test_qmca.py プロジェクト: zenandrea/qmcpack
def test_join():
    exe = get_exe()

    enter('dmc')

    command = "{} -e 5 -j '1 3' -q ev --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
               LocalEnergy                 Variance                   ratio 
dmc  series 0 -10.48910618 +/- 0.00714379  0.45789123 +/- 0.04510618  0.0437 
dmc  series 1 -10.53022752 +/- 0.00073527  0.38410495 +/- 0.00082972  0.0365 
        '''

    assert (text_eq(out, out_ref))

    leave()
コード例 #7
0
ファイル: test_qmca.py プロジェクト: zenandrea/qmcpack
def test_selected_quantities():
    exe = get_exe()

    enter('vmc')

    command = "{} -e 5 -q 'e k p' --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
        vmc  series 0 
          LocalEnergy           =      -10.45972798 +/-       0.00380164 
          Kinetic               =       11.08225203 +/-       0.02281909 
          LocalPotential        =      -21.54198001 +/-       0.02390850 
        '''

    assert (text_eq(out, out_ref))

    leave()
コード例 #8
0
ファイル: test_qmca.py プロジェクト: zenandrea/qmcpack
def test_multiple_equilibration():
    exe = get_exe()

    enter('dmc')

    command = "{} -e '5 10 15 20' -q ev --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
              LocalEnergy                 Variance                   ratio 
dmc series 0 -10.48910618 +/- 0.00714379  0.45789123 +/- 0.04510618  0.0437 
dmc series 1 -10.53167630 +/- 0.00163992  0.38531028 +/- 0.00162825  0.0366 
dmc series 2 -10.53061971 +/- 0.00123791  0.38172188 +/- 0.00124608  0.0362 
dmc series 3 -10.52807733 +/- 0.00122687  0.38565052 +/- 0.00196074  0.0366 
        '''

    assert (text_eq(out, out_ref))

    leave()
コード例 #9
0
ファイル: test_qmca.py プロジェクト: PDoakORNL/qmcpack
def test_energy_variance():
    exe = get_exe()

    enter('opt')

    command = sys.executable + " {} -e 5 -q ev --fp=16.8f *scalar*".format(exe)
    out, err, rc = execute(command)

    out_ref = '''
              LocalEnergy                 Variance                   ratio 
opt series 0 -10.44922550 +/- 0.00475437  0.60256216 +/- 0.01476264  0.0577 
opt series 1 -10.45426389 +/- 0.00320561  0.40278743 +/- 0.01716415  0.0385 
opt series 2 -10.45991696 +/- 0.00271802  0.39865602 +/- 0.00934316  0.0381 
opt series 3 -10.45830307 +/- 0.00298106  0.38110459 +/- 0.00529809  0.0364 
opt series 4 -10.46298481 +/- 0.00561322  0.38927957 +/- 0.01204068  0.0372 
opt series 5 -10.46086055 +/- 0.00375811  0.39354343 +/- 0.00913372  0.0376 
        '''

    assert (text_eq(out, out_ref))

    leave()
コード例 #10
0
    def test_fit():
        import os

        tpath = testing.setup_unit_test_output_directory('qmc_fit', 'test_fit')

        exe = testing.executable_path('qmc-fit')

        qa_files_path = testing.unit_test_file_path('qmcpack_analyzer',
                                                    'diamond_gamma/dmc')
        command = 'rsync -a {} {}'.format(qa_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.in.xml')
        assert (os.path.exists(dmc_infile))

        command = "{} ts --noplot -e 10 -s 1 -t '0.02 0.01 0.005' {}/*scalar*".format(
            exe, dmc_path)

        out, err, rc = execute(command)

        out_ref = '''
            fit function  : linear
            fitted formula: (-10.5271 +/- 0.0021) + (-0.28 +/- 0.17)*t
            intercept     : -10.5271 +/- 0.0021  Ha
            '''

        def process_text(t):
            return t.replace('(', ' ( ').replace(')', ' ) ')

        #end def process_text

        out = process_text(out)
        out_ref = process_text(out_ref)

        assert (text_eq(out, out_ref, atol=1e-2, rtol=1e-2))
コード例 #11
0
ファイル: test_pyscf_input.py プロジェクト: zenandrea/qmcpack
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))
コード例 #12
0
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()
コード例 #13
0
ファイル: test_pyscf_input.py プロジェクト: camelto2/qmcpack
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))
コード例 #14
0
ファイル: test_pyscf_input.py プロジェクト: camelto2/qmcpack
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))
コード例 #15
0
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 = sys.executable+' {} 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 = sys.executable+' {} complete {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    command = sys.executable+' {} 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 = sys.executable+' {} reset {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    command = sys.executable+' {} set setup sent_files submitted {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    command = sys.executable+' {} 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 = sys.executable+' {} complete {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    command = sys.executable+' {} unset got_output analyzed {}'.format(exe,simp_path)
    out,err,rc = execute(command)

    command = sys.executable+' {} 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()
コード例 #16
0
def test_text_checks():
    from testing import text_diff, text_eq, text_neq, value_diff

    assert (id(text_diff) == id(text_neq))

    should_agree = []
    should_disagree = []

    shift = 1e-8

    # aphorism test set
    aphorism = 'Genius is {} percent inspiration and {} percent perspiration.'

    stretched_aphorism = '''
        Genius   is 
    {}   percent inspiration    and 
       {}      percent              perspiration.
        '''

    aphorisms = [aphorism, stretched_aphorism]
    ovals = ['one', 1, 1.0, 1.00001]
    nvals = ['ninety-nine', 99, 99.0, 99.00001]

    nbef = len(should_agree)
    for a1 in aphorisms:
        for a2 in aphorisms:
            for o in ovals:
                for n in nvals:
                    t1 = a1.format(o, n)
                    t2 = a2.format(o, n)
                    should_agree.append((t1, t2))
                    if isinstance(o, float) or isinstance(n, float):
                        if isinstance(o, float):
                            o += shift
                        #end if
                        if isinstance(n, float):
                            n += shift
                        #end if
                        t12 = a1.format(o, n)
                        t22 = a2.format(o, n)
                        should_agree.append((t1, t12))
                        should_agree.append((t2, t22))
                        should_agree.append((t12, t22))
                    #end if
                #end for
            #end for
        #end for
    #end for
    naft = len(should_agree)
    assert (naft - nbef == 208)

    nbef = len(should_disagree)
    for a1 in aphorisms:
        for a2 in aphorisms:
            for o1, n1 in zip(ovals, nvals):
                for o2, n2 in zip(ovals, nvals):
                    if value_diff((o1, n1), (o2, n2)):
                        t1 = a1.format(o1, n1)
                        t2 = a2.format(o2, n2)
                        should_disagree.append((t1, t2))
                    #end if
                #end for
            #end for
        #end for
    #end for
    naft = len(should_disagree)
    assert (naft - nbef == 48)

    # matrix test set
    identical_matrices = [
        '''
        [[ 1.0,2.,3.0 ],
         [ 4.,5.0,6.  ],
         [ 7.0,8. ,9. ]]
        ''',
        '''
        [[ 1.000, 2.000, 3.000 ],
         [ 4.000, 5.000, 6.000 ],
         [ 7.000, 8.000, 9.000 ]]
        ''',
        '''
        [[ 1.0e+00, 2.0, 3.0e+00 ],
         [ 4.0e+00, 5.0, 6.0e+00 ],
         [ 7.0e+00, 8.0, 9.0e+00 ]]
        ''',
        '''
        [[ 0.1e+01  , 200E-02  , 30e-01   ],
         [ 0.04E+02 , 5.       , 0.6e+01  ],
         [ 7.       , 0.008e+03, 9000E-03 ]]
        ''',
        '''
        [[ 0.999999998, 2.000000236, 3.000000239 ],
         [ 4.000000234, 5.000000328, 5.999999013 ],
         [ 7.000000145, 8.000000100, 9.000000000 ]]
        ''',
    ]
    nbef = len(should_agree)
    for m1 in identical_matrices:
        for m2 in identical_matrices:
            should_agree.append((m1, m2))
        #end for
    #end for
    naft = len(should_agree)
    assert (naft - nbef == 25)

    distinct_matrices = [
        '''
        [[ 1.0,2.,3.0 ],
         [ 4.,5.0,6.  ],
         [ 7.0,8. ,9. ]]
        ''',
        '''
        [[ 1.0,2.,3.0 ],
         [ 4.,5.0,6   ],
         [ 7.0,8. ,9. ]]
        ''',
        '''
        [[ 1.0,2.,3.0 ],
         [ 4.,5.0,6.  ],
         [ 7.0,8. ,9. ]],
        ''',
        '''
        [[ 1.000, 2.000, 3.000 ],
         [ 4.000, 5.000, 6.000 ],
         [ 7.000, 8.001, 9.000 ]]
        ''',
        '''
        [[ 1.0e+00, 2.0, 3.0e+00 ],
         [ 4.0e+00, 5.0, 6.0e+01 ],
         [ 7.0e+00, 8.0, 9.0e+00 ]]
        ''',
        '''
        [[ 0.1e+01  , 200E-02  , 30e-01   ],
         [ 0.04E+02 , 5.       , 0.6e+01  ],
         [ 7.       , 0.008e+03, 9001E-03 ]]
        ''',
        '''
        [[ 0.999999998, 2.000000236, 3.000000239 ],
         [ 4.000004234, 5.000000328, 5.999999013 ],
         [ 7.000000145, 8.000000100, 9.000000000 ]]
        ''',
    ]
    nbef = len(should_disagree)
    for m1 in distinct_matrices:
        for m2 in distinct_matrices:
            if id(m1) != id(m2):
                should_disagree.append((m1, m2))
            #end if
        #end for
    #end for
    naft = len(should_disagree)
    assert (naft - nbef == 42)

    # test text_eq functionality
    for t1, t2 in should_agree:
        assert (text_eq(t1, t2))
        assert (not text_neq(t1, t2))
    #end for

    for t1, t2 in should_disagree:
        assert (not text_eq(t1, t2))
        assert (text_neq(t1, t2))
コード例 #17
0
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()
コード例 #18
0
ファイル: test_qdens_radial.py プロジェクト: camelto2/qmcpack
    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))
コード例 #19
0
ファイル: test_qdens.py プロジェクト: camelto2/qmcpack
    def test_density():
        import os

        tpath = testing.setup_unit_test_output_directory('qdens','test_density')

        exe = testing.executable_path('qdens')

        qa_files_path = testing.unit_test_file_path('qmcpack_analyzer','diamond_gamma/dmc')
        command = 'rsync -a {} {}'.format(qa_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.in.xml')
        assert(os.path.exists(dmc_infile))

        files_bef = '''
    dmc.err     dmc.s000.scalar.dat  dmc.s001.stat.h5     dmc.s003.scalar.dat
    dmc.in.xml  dmc.s000.stat.h5     dmc.s002.scalar.dat  dmc.s003.stat.h5
    dmc.out     dmc.s001.scalar.dat  dmc.s002.stat.h5
        '''.split()

        assert(check_value_eq(set(os.listdir(dmc_path)),set(files_bef)))

        command = '{0} -v -e 4 -f xsf -i {1}/dmc.in.xml {1}/*stat.h5'.format(exe,dmc_path)

        out,err,rc = execute(command)

        files_aft = '''
            dmc.err                           dmc.s001.stat.h5
            dmc.in.xml                        dmc.s002.scalar.dat
            dmc.out                           dmc.s002.SpinDensity_d-err.xsf
            dmc.s000.scalar.dat               dmc.s002.SpinDensity_d+err.xsf
            dmc.s000.SpinDensity_d-err.xsf    dmc.s002.SpinDensity_d.xsf
            dmc.s000.SpinDensity_d+err.xsf    dmc.s002.SpinDensity_u-d-err.xsf
            dmc.s000.SpinDensity_d.xsf        dmc.s002.SpinDensity_u-d+err.xsf
            dmc.s000.SpinDensity_u-d-err.xsf  dmc.s002.SpinDensity_u+d-err.xsf
            dmc.s000.SpinDensity_u-d+err.xsf  dmc.s002.SpinDensity_u+d+err.xsf
            dmc.s000.SpinDensity_u+d-err.xsf  dmc.s002.SpinDensity_u-d.xsf
            dmc.s000.SpinDensity_u+d+err.xsf  dmc.s002.SpinDensity_u+d.xsf
            dmc.s000.SpinDensity_u-d.xsf      dmc.s002.SpinDensity_u-err.xsf
            dmc.s000.SpinDensity_u+d.xsf      dmc.s002.SpinDensity_u+err.xsf
            dmc.s000.SpinDensity_u-err.xsf    dmc.s002.SpinDensity_u.xsf
            dmc.s000.SpinDensity_u+err.xsf    dmc.s002.stat.h5
            dmc.s000.SpinDensity_u.xsf        dmc.s003.scalar.dat
            dmc.s000.stat.h5                  dmc.s003.SpinDensity_d-err.xsf
            dmc.s001.scalar.dat               dmc.s003.SpinDensity_d+err.xsf
            dmc.s001.SpinDensity_d-err.xsf    dmc.s003.SpinDensity_d.xsf
            dmc.s001.SpinDensity_d+err.xsf    dmc.s003.SpinDensity_u-d-err.xsf
            dmc.s001.SpinDensity_d.xsf        dmc.s003.SpinDensity_u-d+err.xsf
            dmc.s001.SpinDensity_u-d-err.xsf  dmc.s003.SpinDensity_u+d-err.xsf
            dmc.s001.SpinDensity_u-d+err.xsf  dmc.s003.SpinDensity_u+d+err.xsf
            dmc.s001.SpinDensity_u+d-err.xsf  dmc.s003.SpinDensity_u-d.xsf
            dmc.s001.SpinDensity_u+d+err.xsf  dmc.s003.SpinDensity_u+d.xsf
            dmc.s001.SpinDensity_u-d.xsf      dmc.s003.SpinDensity_u-err.xsf
            dmc.s001.SpinDensity_u+d.xsf      dmc.s003.SpinDensity_u+err.xsf
            dmc.s001.SpinDensity_u-err.xsf    dmc.s003.SpinDensity_u.xsf
            dmc.s001.SpinDensity_u+err.xsf    dmc.s003.stat.h5
            dmc.s001.SpinDensity_u.xsf
            '''.split()

        assert(check_value_eq(set(os.listdir(dmc_path)),set(files_aft),verbose=True))

        tot_file = os.path.join(dmc_path,'dmc.s003.SpinDensity_u+d.xsf')
        pol_file = os.path.join(dmc_path,'dmc.s003.SpinDensity_u-d.xsf')

        tot = open(tot_file,'r').read()
        pol = open(pol_file,'r').read()

        tot_ref = '''
             CRYSTAL
             PRIMVEC 
                 1.78500000   1.78500000   0.00000000
                -0.00000000   1.78500000   1.78500000
                 1.78500000  -0.00000000   1.78500000
             PRIMCOORD 
               2 1
                 6   0.00000000   0.00000000   0.00000000
                 6   0.89250000   0.89250000   0.89250000
             BEGIN_BLOCK_DATAGRID_3D
               density
               BEGIN_DATAGRID_3D_density
                 4 4 4
                 0.59500000   0.59500000   0.59500000
                 1.78500000   1.78500000   0.00000000
                -0.00000000   1.78500000   1.78500000
                 1.78500000  -0.00000000   1.78500000
                   0.73126076   0.62407496   0.51676366   0.73126076
                   0.62575089   0.19225114   0.18686389   0.62575089
                   0.51847569   0.18457799   0.42203355   0.51847569
                   0.73126076   0.62407496   0.51676366   0.73126076
                   0.62659840   0.19325900   0.18422995   0.62659840
                   0.19219866   0.04873728   0.13184395   0.19219866
                   0.18474638   0.13013188   0.10227670   0.18474638
                   0.62659840   0.19325900   0.18422995   0.62659840
                   0.51793019   0.18615766   0.41806405   0.51793019
                   0.18425005   0.13092538   0.10088238   0.18425005
                   0.41967003   0.10133434   0.14471118   0.41967003
                   0.51793019   0.18615766   0.41806405   0.51793019
                   0.73126076   0.62407496   0.51676366   0.73126076
                   0.62575089   0.19225114   0.18686389   0.62575089
                   0.51847569   0.18457799   0.42203355   0.51847569
                   0.73126076   0.62407496   0.51676366   0.73126076
               END_DATAGRID_3D_density
             END_BLOCK_DATAGRID_3D
            '''

        pol_ref = '''
             CRYSTAL
             PRIMVEC 
                 1.78500000   1.78500000   0.00000000
                -0.00000000   1.78500000   1.78500000
                 1.78500000  -0.00000000   1.78500000
             PRIMCOORD 
               2 1
                 6   0.00000000   0.00000000   0.00000000
                 6   0.89250000   0.89250000   0.89250000
             BEGIN_BLOCK_DATAGRID_3D
               density
               BEGIN_DATAGRID_3D_density
                 4 4 4
                 0.59500000   0.59500000   0.59500000
                 1.78500000   1.78500000   0.00000000
                -0.00000000   1.78500000   1.78500000
                 1.78500000  -0.00000000   1.78500000
                   0.00106753   0.00015792  -0.00122859   0.00106753
                  -0.00003402   0.00018762  -0.00051347  -0.00003402
                   0.00154254   0.00067654   0.00073434   0.00154254
                   0.00106753   0.00015792  -0.00122859   0.00106753
                   0.00263956   0.00079744  -0.00118289   0.00263956
                  -0.00039348  -0.00026396  -0.00069392  -0.00039348
                   0.00087929   0.00000719   0.00113934   0.00087929
                   0.00263956   0.00079744  -0.00118289   0.00263956
                  -0.00013655  -0.00041508  -0.00235212  -0.00013655
                   0.00003805  -0.00025962  -0.00133495   0.00003805
                   0.00040692   0.00051699  -0.00198263   0.00040692
                  -0.00013655  -0.00041508  -0.00235212  -0.00013655
                   0.00106753   0.00015792  -0.00122859   0.00106753
                  -0.00003402   0.00018762  -0.00051347  -0.00003402
                   0.00154254   0.00067654   0.00073434   0.00154254
                   0.00106753   0.00015792  -0.00122859   0.00106753
               END_DATAGRID_3D_density
             END_BLOCK_DATAGRID_3D
            '''

        assert(text_eq(tot,tot_ref,atol=1e-7))
        assert(text_eq(pol,pol_ref,atol=1e-7))
コード例 #20
0
def test_projwfc_analyzer():
    import os
    from generic import obj
    from pwscf_postprocessors import ProjwfcAnalyzer

    tpath = testing.setup_unit_test_output_directory(
        test      = 'pwscf_postprocessor_analyzers',
        subtest   = 'test_projwfc_analyzer',
        file_sets = ['pwf.in','pwf.out'],
        )

    projwfc_in = os.path.join(tpath,'pwf.in')

    pa = ProjwfcAnalyzer(projwfc_in)

    del pa.info.path

    pa_ref = obj(
        info = obj(
            infile          = 'pwf.in',
            initialized     = True,
            outfile         = 'pwf.out',
            strict          = False,
            warn            = False,
            ),
        input = obj(
            projwfc = obj(
                lwrite_overlaps = True,
                outdir          = 'pwscf_output',
                prefix          = 'pwscf',
                ),
            ),
        )

    assert(object_eq(pa.to_obj(),pa_ref))


    pa = ProjwfcAnalyzer(projwfc_in,analyze=True)

    del pa.info.path

    pa_ref = obj(
        info = obj(
            infile      = 'pwf.in',
            initialized = True,
            outfile     = 'pwf.out',
            strict      = False,
            warn        = False,
            ),
        input = obj(
            projwfc = obj(
                lwrite_overlaps = True,
                outdir          = 'pwscf_output',
                prefix          = 'pwscf',
                ),
            ),
        lowdin = obj({
            0 : obj(
                down = obj({
                    'charge' : 1.9988,
                    'd'      : 0.0,
                    'dx2-y2' : 0.0,
                    'dxy'    : 0.0,
                    'dxz'    : 0.0,
                    'dyz'    : 0.0,
                    'dz2'    : 0.0,
                    'p'      : 0.999,
                    'px'     : 0.3318,
                    'py'     : 0.3336,
                    'pz'     : 0.3336,
                    's'      : 0.9998,
                    }),
                pol = obj({
                    'charge' : 2.0001,
                    'd'      : 0.0,
                    'dx2-y2' : 0.0,
                    'dxy'    : 0.0,
                    'dxz'    : 0.0,
                    'dyz'    : 0.0,
                    'dz2'    : 0.0,
                    'p'      : 1.9999,
                    'px'     : 0.6678,
                    'py'     : 0.666,
                    'pz'     : 0.666,
                    's'      : 0.0001,
                    }),
                tot = obj({
                    'charge' : 5.9977,
                    'd'      : 0.0,
                    'dx2-y2' : 0.0,
                    'dxy'    : 0.0,
                    'dxz'    : 0.0,
                    'dyz'    : 0.0,
                    'dz2'    : 0.0,
                    'p'      : 3.9979,
                    'px'     : 1.3314,
                    'py'     : 1.3332,
                    'pz'     : 1.3332,
                    's'      : 1.9997,
                    }),
                up = obj({
                    'charge' : 3.9989,
                    'd'      : 0.0,
                    'dx2-y2' : 0.0,
                    'dxy'    : 0.0,
                    'dxz'    : 0.0,
                    'dyz'    : 0.0,
                    'dz2'    : 0.0,
                    'p'      : 2.9989,
                    'px'     : 0.9996,
                    'py'     : 0.9996,
                    'pz'     : 0.9996,
                    's'      : 0.9999,
                    }),
                )
            }),
        states = obj(
            elem    = ['S'],
            nstates = 9,
            ),
        )

    assert(object_eq(pa.to_obj(),pa_ref))


    lowdin_file = os.path.join(tpath,'pwf.lowdin')

    pa.write_lowdin(lowdin_file)

    text = open(lowdin_file,'r').read()

    text_ref = '''
        nup+ndn = 5.9977
        nup-ndn = 2.0001
        
        tot
            0   S   6.00  s( 2.00)p( 4.00)d( 0.00)
        
        pol
            0   S   2.00  s( 0.00)p( 2.00)d( 0.00)
        
        up
            0   S   4.00  s( 1.00)p( 3.00)d( 0.00)
        
        down
            0   S   2.00  s( 1.00)p( 1.00)d( 0.00)
        '''

    def process_text(t):
        return t.replace('(',' ( ').replace(')',' ) ')
    #end def process_text

    text     = process_text(text)
    text_ref = process_text(text_ref)

    assert(text_eq(text,text_ref))


    lowdin_file = os.path.join(tpath,'pwf.lowdin_long')

    pa.write_lowdin(lowdin_file,long=True)

    text = open(lowdin_file,'r').read()

    text_ref = '''
        nup+ndn = 5.9977
        nup-ndn = 2.0001
        
        tot
            0   S   6.00  s( 2.00)px( 1.33)py( 1.33)pz( 1.33)dx2-y2( 0.00)dxy( 0.00)dxz( 0.00)dyz( 0.00)dz2( 0.00)
        
        pol
            0   S   2.00  s( 0.00)px( 0.67)py( 0.67)pz( 0.67)dx2-y2( 0.00)dxy( 0.00)dxz( 0.00)dyz( 0.00)dz2( 0.00)
        
        up
            0   S   4.00  s( 1.00)px( 1.00)py( 1.00)pz( 1.00)dx2-y2( 0.00)dxy( 0.00)dxz( 0.00)dyz( 0.00)dz2( 0.00)
        
        down
            0   S   2.00  s( 1.00)px( 0.33)py( 0.33)pz( 0.33)dx2-y2( 0.00)dxy( 0.00)dxz( 0.00)dyz( 0.00)dz2( 0.00)
        '''

    text     = process_text(text)
    text_ref = process_text(text_ref)

    assert(text_eq(text,text_ref))