Beispiel #1
0
def test_basissets():
    from basisset import BasisSets
    from basisset import BasisFile
    from basisset import gamessBasisFile

    # empty initialization
    BasisSets()
    BasisFile()
    gamessBasisFile()

    filenames = get_filenames()
    files = get_files()
    f = [files[fn] for fn in filenames]

    # standard initialization
    divert_nexus_log()
    bf = BasisFile(f[1])
    gbf = gamessBasisFile(f[0])
    bs = BasisSets(f[2:] + [bf, gbf])
    restore_nexus_log()

    assert (bf.element == 'Fe')
    assert (bf.filename == 'Fe.aug-cc-pwcv5z-dk.0.gbs')

    assert (gbf.element == 'Fe')
    assert (gbf.filename == 'Fe.aug-cc-pwcv5z-dk.0.bas')
    assert (gbf.text.startswith('IRON'))
    assert (gbf.text.endswith('1         1.3776500              1.0000000'))
    assert (len(gbf.text.strip()) == 21135)

    for fn in filenames:
        assert (fn in bs)
        assert (isinstance(bs[fn], BasisFile))
        if fn.endswith('.bas'):
            assert (isinstance(bs[fn], gamessBasisFile))
Beispiel #2
0
def test_keyspec_groups():
    from gamess_input import check_keyspec_groups

    divert_nexus_log()

    check_keyspec_groups()

    restore_nexus_log()
Beispiel #3
0
def test_write_splash():
    from nexus_base import NexusCore
    log = divert_nexus_log()
    nc = NexusCore()
    assert(not nc.wrote_splash)
    nc.write_splash()
    assert('Nexus' in log.contents())
    assert('Please cite:' in log.contents())
    assert(nc.wrote_splash)
    restore_nexus_log()
def test_check_dependencies():
    from simulation import Simulation
    from project_manager import ProjectManager

    from test_simulation_module import get_test_workflow

    divert_nexus_log()

    sims = get_test_workflow(1)

    pm = ProjectManager()
    pm.add_simulations(sims.list())

    idc = id(pm.cascades)
    idp = id(pm.progressing_cascades)

    pm.check_dependencies()

    restore_nexus_log()

    Simulation.clear_all_sims()
def test_resolve_file_collisions():
    from generic import NexusError
    from simulation import Simulation
    from project_manager import ProjectManager

    from test_simulation_module import get_test_workflow, n_test_workflows

    divert_nexus_log()

    sims = []
    for n in range(n_test_workflows):
        sims.extend(get_test_workflow(n).list())
    #end for

    pm = ProjectManager()
    pm.add_simulations(sims)

    pm.resolve_file_collisions()

    s1 = sims[len(sims) // 2]
    s2 = sims[len(sims) // 2 + 1]

    s2.locdir = s1.locdir
    s2.outfile = s1.outfile

    try:
        pm.resolve_file_collisions()
        raise FailedTest
    except NexusError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try

    restore_nexus_log()

    Simulation.clear_all_sims()
Beispiel #6
0
def test_enter_leave():
    import os
    from nexus_base import NexusCore

    tpath = testing.setup_unit_test_output_directory('nexus_base','test_enter_leave')

    cwd = os.getcwd()

    log = divert_nexus_log()

    nc = NexusCore()

    nc.enter(tpath)
    tcwd = os.getcwd()
    assert(tcwd==tpath)
    assert('Entering' in log.contents())
    assert(tpath in log.contents())

    nc.leave()
    assert(os.getcwd()==cwd)

    restore_nexus_log()
Beispiel #7
0
def test_logging():
    from generic import log,message,warn,error
    from generic import generic_settings,NexusError

    # send messages to object rather than stdout
    divert_nexus_log()

    logfile = generic_settings.devlog

    # test log
    #   simple message
    s = 'simple message'
    logfile.reset()
    log(s)
    assert(logfile.s==s+'\n')

    #   list of items
    items = ['a','b','c',1,2,3]
    logfile.reset()
    log(*items)
    assert(logfile.s=='a b c 1 2 3 \n')

    #   message with indentation
    s = 'a message\nwith indentation'
    logfile.reset()
    log(s,indent='  ')
    assert(logfile.s=='  a message\n  with indentation\n')

    logfile.reset()
    log(s,indent='msg: ')
    assert(logfile.s=='msg: a message\nmsg: with indentation\n')
    
    #   writing to separate log files
    logfile2 = FakeLog()
    s1 = 'message to log 1'
    s2 = 'message to log 2'
    logfile.reset()
    logfile2.reset()
    log(s1)
    assert(logfile.s==s1+'\n')
    assert(logfile2.s=='')

    logfile.reset()
    logfile2.reset()
    log(s2,logfile=logfile2)
    assert(logfile.s=='')
    assert(logfile2.s==s2+'\n')
    

    # test warn
    logfile.reset()
    s = 'this is a warning'
    warn(s)
    so = '''
  warning:
    this is a warning
'''
    assert(logfile.s==so)
    logfile.reset()
    s = 'this is a warning'
    warn(s,header='Special')
    so = '''
  Special warning:
    this is a warning
'''
    assert(logfile.s==so)

    # test error
    #   in testing environment, should raise an error
    try:
        error('testing environment')
        raise FailedTest
    except NexusError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try
    #   in standard/user environment, should print message
    generic_settings.raise_error = False
    logfile.reset()
    error('this is an error',header='User',exit=False)
    so = '''
  User error:
    this is an error
'''
    assert(logfile.s==so)
    generic_settings.raise_error = True
    #   in testing environment, should raise an error
    try:
        error('testing environment')
        raise FailedTest
    except NexusError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try

    restore_nexus_log()
Beispiel #8
0
def test_intrinsics():
    # test object_interface functions
    import os
    from generic import obj,object_interface
    from generic import generic_settings,NexusError
    from numpy import array,bool_

    tpath = testing.setup_unit_test_output_directory('generic','test_intrinsics')

    # test object set/get
    # make a simple object
    o = obj()
    o.a = 1
    o.b = 'b'
    o['c'] = (1,1,1)
    o[3,4,5] = (5,6,7)

    # test member values
    assert(o.a==1)
    assert(o.b=='b')
    assert(o.c==(1,1,1))
    assert(o[3,4,5]==(5,6,7))

    # test member presence and length
    assert('a' in o)
    assert(2 not in o)
    assert(len(o)==4)
    del o.a
    assert('a' not in o)
    assert(len(o)==3)
    try:
        del o.d
        raise FailedTest
    except AttributeError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try

    # test add/access failures
    try: # add unhashable type
        o[{1:2,3:4}] = 5
        raise FailedTest
    except TypeError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try
    try: # access missing member
        v = o.d
        raise FailedTest
    except AttributeError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try
    try: # access missing member
        v = o['d']
        raise FailedTest
    except KeyError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try

    # test iterability
    # test list-like iterability
    l = list()
    for v in o:
        l.append(v)
    #end for
    l = set(l)
    l2 = {'b', (1, 1, 1), (5, 6, 7)}
    assert(l2==l)

    # test dict-like iterability
    d = dict()
    for k,v in o.items():
        d[k] = v
    #end for
    o2 = obj()
    o2.__dict__ = d
    assert(object_eq(o,o2))
    assert(set(o.keys())==set(d.keys()))
    assert(set(o.values())==set(d.values()))
    assert(set(o.items())==set(d.items()))

    # test repr
    ro = '''
  b                     str                 
  c                     tuple               
  (3, 4, 5)             tuple               
'''
    assert(repr(o)==ro[1:])
    o2 = obj(
        a = obj(a1=1,a2=2,a3=3),
        b = obj(b1='b1',b2='b2'),
        c = obj(c1=5,c2=('a',3,4)),
        d = array([3,4,5],dtype=int),
        )
    ro2 = '''
  a                     obj                 
  b                     obj                 
  c                     obj                 
  d                     ndarray             
'''
    assert(repr(o2)==ro2[1:])

    # test str
    so = '''
  b               = b
  c               = (1, 1, 1)
  (3, 4, 5)       = (5, 6, 7)
'''
    assert(str(o)==so[1:])
    so2 = '''
  d               = [3 4 5]
  a
    a1              = 1
    a2              = 2
    a3              = 3
  end a
  b
    b1              = b1
    b2              = b2
  end b
  c
    c1              = 5
    c2              = ('a', 3, 4)
  end c
'''
    assert(str(o2)==so2[1:])
    o3 = o2

    # test tree
    #   not committed to output, only check execution
    assert(isinstance(o2.tree(),str))
    assert(isinstance(o2.tree(depth=1),str))
    assert(isinstance(o2.tree(types=True),str))
    assert(isinstance(o2.tree(all=True),str))
    assert(isinstance(o2.tree(nindent=2),str))

    # test deepcopy
    o2 = o.copy()
    assert(id(o)!=id(o2))
    assert(object_eq(o,o2))
    o2.a=1
    assert(object_neq(o,o2))
    
    # test eq
    assert(o==o2)
    o4 = o3.copy()
    v = o3==o4
    assert(isinstance(v,bool_))
    assert(bool(v))
    assert(object_eq(o3,o4))

    # test clear
    o2.clear()
    assert(len(o2)==0)
    assert('a' not in o2)

    # test save/load
    save_file = os.path.join(tpath,'o.p')
    o.save(save_file)
    o2 = obj()
    o2.load(save_file)
    assert(object_eq(o,o2))

    # test class-level set/get methods
    class objint(object_interface):
        a = 1
        b = 'b'
        c = (1,1,1)
    #end class objint

    # test class_has
    assert(objint.class_has('c'))

    # test class_get
    assert(objint.class_get('c')==(1,1,1))
    try:
        val = objint.class_get('d')
        raise FailedTest
    except AttributeError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try

    # test class_keys
    ck = objint.class_keys()
    for v in 'abc':
        assert(v in ck)
    #end for

    # test class_set_single
    objint.class_set_single('d',1.34)
    assert(objint.class_has('d'))

    # test class_set
    objint.class_set(
        e = 45,
        f = 'a phrase',
        g = {4:6,'a':2}
        )
    for v in 'efg':
        assert(objint.class_has(v))
    #end for

    # test class_set_optional
    objint.class_set_optional(h=2)
    assert(objint.class_has('h'))
    assert(objint.class_get('h')==2)
    objint.class_set_optional(a=6)
    assert(objint.class_get('a')==1)
    

    # test logging functions

    # test open log, write, close log
    o = obj()
    o.open_log('log.out')
    s = 'log output'
    o.write(s)
    o.close_log()
    f = open('log.out','r')
    so = f.read()
    f.close()
    os.remove('log.out')
    assert(so==s)

    # send messages to object rather than stdout
    divert_nexus_log()
    logfile = object_interface._logfile

    #   simple message
    class DerivedObj(obj):
        None
    #end class DerivedObj
    o = DerivedObj()
    s = 'simple message'
    logfile.reset()
    o.log(s)
    assert(logfile.s==s+'\n')

    #   list of items
    items = ['a','b','c',1,2,3]
    logfile.reset()
    o.log(*items)
    assert(logfile.s=='a b c 1 2 3 \n')

    #   message with indentation
    s = 'a message\nwith indentation'
    logfile.reset()
    o.log(s,indent='  ')
    assert(logfile.s=='  a message\n  with indentation\n')

    logfile.reset()
    o.log(s,indent='msg: ')
    assert(logfile.s=='msg: a message\nmsg: with indentation\n')
    
    #   writing to separate log files
    logfile2 = FakeLog()
    s1 = 'message to log 1'
    s2 = 'message to log 2'
    logfile.reset()
    logfile2.reset()
    o.log(s1)
    assert(logfile.s==s1+'\n')
    assert(logfile2.s=='')

    logfile.reset()
    logfile2.reset()
    o.log(s2,logfile=logfile2)
    assert(logfile.s=='')
    assert(logfile2.s==s2+'\n')
    

    # test warn
    logfile.reset()
    s = 'this is a warning'
    o.warn(s)
    so = '''
  DerivedObj warning:
    this is a warning
'''
    assert(logfile.s==so)
    logfile.reset()
    s = 'this is a warning'
    o.warn(s,header='Special')
    so = '''
  Special warning:
    this is a warning
'''
    assert(logfile.s==so)

    # test error
    #   in testing environment, should raise an error
    try:
        o.error('testing environment')
        raise FailedTest
    except NexusError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try
    #   in standard/user environment, should print message
    generic_settings.raise_error = False
    logfile.reset()
    o.error('this is an error',exit=False)
    so = '''
  DerivedObj error:
    this is an error
'''
    assert(logfile.s==so)
    logfile.reset()
    o.error('this is an error',header='User',exit=False)
    so = '''
  User error:
    this is an error
'''
    assert(logfile.s==so)
    generic_settings.raise_error = True
    #   in testing environment, should raise an error
    try:
        o.error('testing environment')
        raise FailedTest
    except NexusError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try

    # restore logging function
    restore_nexus_log()
Beispiel #9
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()
Beispiel #10
0
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()
Beispiel #11
0
def test_pseudopotentials():
    from pseudopotential import Pseudopotentials
    from pseudopotential import PseudoFile
    from pseudopotential import gamessPPFile

    filenames = get_filenames()
    files = get_files()

    filepaths = [files[fn] for fn in filenames]

    # empty initialization
    Pseudopotentials()
    PseudoFile()
    gamessPPFile()

    # standard initialization
    divert_nexus_log()
    pps = Pseudopotentials(filepaths)
    restore_nexus_log()

    for fn in filenames:
        assert (fn in pps)
        pp = pps[fn]
        assert (isinstance(pp, PseudoFile))
        if fn.endswith('.gms'):
            assert (isinstance(pp, gamessPPFile))
        #end if
        assert (pp.element == 'C')
        assert (pp.element_label == 'C')
        assert (pp.filename == fn)
    #end for

    basis_ref = '''s 9 1.00
1 0.051344     0.013991
2 0.102619     0.169852
3 0.205100     0.397529
4 0.409924     0.380369
5 0.819297     0.180113
6 1.637494     -0.033512
7 3.272791     -0.121499
8 6.541187     0.015176
9 13.073594     -0.000705
s 1 1.00
1 0.098302     1.000000
s 1 1.00
1 0.232034     1.000000
s 1 1.00
1 0.744448     1.000000
s 1 1.00
1 1.009914     1.000000
p 9 1.00
1 0.029281     0.001787
2 0.058547     0.050426
3 0.117063     0.191634
4 0.234064     0.302667
5 0.468003     0.289868
6 0.935757     0.210979
7 1.871016     0.112024
8 3.741035     0.054425
9 7.480076     0.021931
p 1 1.00
1 0.084047     1.000000
p 1 1.00
1 0.216618     1.000000
p 1 1.00
1 0.576869     1.000000
p 1 1.00
1 1.006252     1.000000
d 1 1.00
1 0.206619     1.000000
d 1 1.00
1 0.606933     1.000000
d 1 1.00
1 1.001526     1.000000
d 1 1.00
1 1.504882     1.000000
f 1 1.00
1 0.400573     1.000000
f 1 1.00
1 1.099564     1.000000
f 1 1.00
1 1.501091     1.000000
g 1 1.00
1 0.797648     1.000000
g 1 1.00
1 1.401343     1.000000
h 1 1.00
1 1.001703     1.000000'''

    pp_ref = '''C-QMC GEN 2 1
3
4.00000000 1 8.35973821
33.43895285 3 4.48361888
-19.17537323 2 3.93831258
1
22.55164191 2 5.02991637'''

    pp = pps['C.BFD.gms']
    assert (pp.basis_text == basis_ref)
    assert (pp.pp_text == pp_ref)