コード例 #1
0
def test_cp2k_txt_vs_dcd():
    # Two exactly equal NPT runs, nstep=16, natoms=57. The dcd run uses
    #   motion/print/trajectory format dcd_aligned_cell
    # the other the default xyz format. So we have
    #   PROJECT-pos-1.dcd
    #   PROJECT-pos-1.xyz
    # Since the cell changes and we use dcd_aligned_cell, the coords from the
    # xyz run are NOT the same as the coords in the dcd file, which HAS to be
    # like this. Only coords_frac can be compared, and coords after the xyz
    # run's cell has been aligned to [[x,0,0],[xy,y,0],[xz,yz,z]].
    dir_xyz = unpack_compressed('files/cp2k/dcd/npt_xyz.tgz')
    dir_dcd = unpack_compressed('files/cp2k/dcd/npt_dcd.tgz')
    tr_xyz = io.read_cp2k_md(pj(dir_xyz, 'cp2k.out'))
    tr_dcd = io.read_cp2k_md_dcd(pj(dir_dcd, 'cp2k.out'))
    for name in ['natoms', 'nstep', 'timestep', 'symbols']:
        assert getattr(tr_xyz, name) == getattr(tr_dcd, name)
    assert tr_xyz.timestep == 1.0
    assert tr_xyz.natoms == 57
    assert tr_xyz.nstep == 16

    # coords are 32bit float in dcd files (single prec, so coords_frac can only
    # be accurate to that precision, which ~1e-8). cryst_const is double
    # precision in the dcd file, so atol can be lower
    assert np.allclose(tr_xyz.coords_frac,
                       tr_dcd.coords_frac,
                       rtol=0,
                       atol=1.5e-7)
    assert np.allclose(tr_xyz.cryst_const,
                       tr_dcd.cryst_const,
                       rtol=0,
                       atol=7e-10)
    assert not np.allclose(tr_xyz.coords, tr_dcd.coords, rtol=0, atol=5e-6)
    assert not np.allclose(tr_xyz.cell, tr_dcd.cell, rtol=0, atol=7e-10)

    # align xyz cell, now cell and coords are the same
    tr_xyz.coords = None
    tr_xyz.cell = None
    tr_xyz.set_all()

    assert np.allclose(tr_xyz.coords_frac,
                       tr_dcd.coords_frac,
                       rtol=0,
                       atol=1.5e-7)
    assert np.allclose(tr_xyz.cryst_const,
                       tr_dcd.cryst_const,
                       rtol=0,
                       atol=7e-10)
    assert np.allclose(tr_xyz.coords, tr_dcd.coords, rtol=0, atol=5e-6)
    assert np.allclose(tr_xyz.cell, tr_dcd.cell, rtol=0, atol=7e-10)
コード例 #2
0
def run(filename, none_attrs=[]):
    # filename = 'files/cpmd/md_bo/cpmd.bo.out'
    # basename = 'cpmd.bo.out'
    # archive  = 'files/cpmd/md_bo.tgz'
    bar = '=' * 78
    print(bar)
    print("@@testing: %s" % filename)
    print(bar)
    basename = os.path.basename(filename)
    archive = os.path.dirname(filename) + '.tgz'
    workdir = unpack_compressed(archive)
    pp = CpmdMDOutputFile(filename=pj(workdir, basename))
    pp.parse()
    assert_attrs_not_none(pp, none_attrs=none_attrs)
    traj = pp.get_traj()
    attrs3d = [
        'coords',
        'coords_frac',
        'forces',
        'cell',
        'stress',
    ]
    for attr_name in traj.attr_lst:
        attr = getattr(traj, attr_name)
        if attr_name not in none_attrs:
            if hasattr(attr, 'ndim'):
                print("%s: ndim: %s, shape: %s" %
                      (attr_name, attr.ndim, attr.shape))
            assert attr is not None, "FAILED - None: %s" % attr_name
            if attr_name in attrs3d:
                assert attr.ndim == 3, "FAILED - not 3d: %s" % attr_name
コード例 #3
0
ファイル: test_pw_md_out.py プロジェクト: elcorto/pwtools
def test_pw_md_out():
    filename = tools.unpack_compressed('files/pw.md.out.gz', prefix=__file__)
    alat = 5.9098 # Bohr
    pp1 = PwMDOutputFile(filename=filename, use_alat=True)
    pp1.parse()
    none_attrs = [\
        'coords_frac',
        ]
    assert_attrs_not_none(pp1, none_attrs=none_attrs)
    assert np.allclose(pp1.timestep, 150.0) # tryd
    traj1 = pp1.get_traj()
    assert_attrs_not_none(traj1)

    pp2 = PwMDOutputFile(filename=filename, 
                         use_alat=False,
                         units={'length': alat*Bohr/Ang})
    pp2.parse()                         
    assert np.allclose(pp2.timestep, 150.0) # tryd
    assert_attrs_not_none(pp2, none_attrs=none_attrs)
    
    # Skip coords and cell b/c they are modified by self.alat and
    # pp1.alat = 1.0, pp2.alat = 5.9098
    attr_lst = common.pop_from_list(pp1.attr_lst, ['coords', 'cell'])
    adae(pp1.__dict__, pp2.__dict__, keys=attr_lst)         
    
    traj2 = pp2.get_traj()
    adae(traj1.__dict__, traj2.__dict__, keys=traj1.attr_lst)

    pp3 = PwMDOutputFile(filename=filename)
    assert alat == pp3.get_alat() # self.use_alat=True default
コード例 #4
0
ファイル: test_cpmd_md.py プロジェクト: elcorto/pwtools
def run(filename, none_attrs=[]):
    # filename = 'files/cpmd/md_bo/cpmd.bo.out'
    # basename = 'cpmd.bo.out'
    # archive  = 'files/cpmd/md_bo.tgz'
    bar = '='*78
    print bar
    print "@@testing: %s" %filename
    print bar
    basename = os.path.basename(filename)
    archive = os.path.dirname(filename) + '.tgz'
    workdir = unpack_compressed(archive)
    pp = CpmdMDOutputFile(filename=pj(workdir, basename))
    pp.parse()
    assert_attrs_not_none(pp, none_attrs=none_attrs)
    traj = pp.get_traj()
    attrs3d = ['coords', 
               'coords_frac', 
               'forces', 
               'cell',
               'stress',
               ]
    for attr_name in traj.attr_lst:
        attr = getattr(traj, attr_name)
        if attr_name not in none_attrs:
            if hasattr(attr, 'ndim'):
                print "%s: ndim: %s, shape: %s" %(attr_name, attr.ndim, attr.shape)
            assert attr is not None, "FAILED - None: %s" %attr_name
            if attr_name in attrs3d:
                assert attr.ndim == 3, "FAILED - not 3d: %s" %attr_name
コード例 #5
0
ファイル: test_pw_md_out.py プロジェクト: zari277/pwtools
def test_pw_md_out():
    filename = tools.unpack_compressed('files/pw.md.out.gz', prefix=__file__)
    alat = 5.9098  # Bohr
    pp1 = PwMDOutputFile(filename=filename, use_alat=True)
    pp1.parse()
    none_attrs = [\
        'coords_frac',
        ]
    assert_attrs_not_none(pp1, none_attrs=none_attrs)
    assert np.allclose(pp1.timestep, 150.0)  # tryd
    traj1 = pp1.get_traj()
    assert_attrs_not_none(traj1)

    pp2 = PwMDOutputFile(filename=filename,
                         use_alat=False,
                         units={'length': alat * Bohr / Ang})
    pp2.parse()
    assert np.allclose(pp2.timestep, 150.0)  # tryd
    assert_attrs_not_none(pp2, none_attrs=none_attrs)

    # Skip coords and cell b/c they are modified by self.alat and
    # pp1.alat = 1.0, pp2.alat = 5.9098
    attr_lst = common.pop_from_list(pp1.attr_lst, ['coords', 'cell'])
    adae(pp1.__dict__, pp2.__dict__, keys=attr_lst)

    traj2 = pp2.get_traj()
    adae(traj1.__dict__, traj2.__dict__, keys=traj1.attr_lst)

    pp3 = PwMDOutputFile(filename=filename)
    assert alat == pp3.get_alat()  # self.use_alat=True default
コード例 #6
0
ファイル: test_pw_scf_out.py プロジェクト: zari277/pwtools
def test_pw_scf_no_forces_stress():
    fn = unpack_compressed('files/pw.scf_no_forces_stress.out.gz')
    pp = PwSCFOutputFile(fn)
    assert pp.get_forces() is None
    assert pp.get_stress() is None
    st = io.read_pw_scf(fn)
    assert st.stress is None
    assert st.forces is None
コード例 #7
0
ファイル: test_pw_scf_out.py プロジェクト: elcorto/pwtools
def test_pw_scf_no_forces_stress():
    fn = unpack_compressed('files/pw.scf_no_forces_stress.out.gz')
    pp = PwSCFOutputFile(fn)
    assert pp.get_forces() is None
    assert pp.get_stress() is None
    st = io.read_pw_scf(fn)
    assert st.stress is None
    assert st.forces is None
コード例 #8
0
ファイル: test_cpmd_scf.py プロジェクト: elcorto/pwtools
def test_cpmd_scf():
    filename = "files/cpmd/scf/cpmd.out"
    basename = os.path.basename(filename)
    archive = os.path.dirname(filename) + ".tgz"
    workdir = unpack_compressed(archive)
    pp = CpmdSCFOutputFile(filename=pj(workdir, basename))
    pp.parse()
    assert_attrs_not_none(pp, none_attrs=[])
コード例 #9
0
ファイル: test_cpmd_scf.py プロジェクト: zari277/pwtools
def test_cpmd_scf():
    filename = 'files/cpmd/scf/cpmd.out'
    basename = os.path.basename(filename)
    archive = os.path.dirname(filename) + '.tgz'
    workdir = unpack_compressed(archive)
    pp = CpmdSCFOutputFile(filename=pj(workdir, basename))
    pp.parse()
    assert_attrs_not_none(pp, none_attrs=[])
コード例 #10
0
def test_read_matdyn_freq_disp():
    # Parse matdyn frequency file. In QE 5.x the path_norm and band structure
    # is also directly written to a file with suffix ".gp", i.e.
    # "matdyn.freq.disp.gp"
    fn = unpack_compressed('files/qe_matdyn_disp/matdyn.freq.disp.gz')
    kk, ff = pwscf.read_matdyn_freq(fn)
    d = np.loadtxt('files/qe_matdyn_disp/matdyn.freq.disp.gp.gz')
    assert np.allclose(kpath.get_path_norm(kk), d[:,0])
    assert np.allclose(ff, d[:,1:])
コード例 #11
0
ファイル: test_cp2k.py プロジェクト: elcorto/pwtools
def test_cp2k_txt_vs_dcd():
    # Two exactly equal NPT runs, nstep=16, natoms=57. The dcd run uses 
    #   motion/print/trajectory format dcd_aligned_cell
    # the other the default xyz format. So we have 
    #   PROJECT-pos-1.dcd
    #   PROJECT-pos-1.xyz
    # Since the cell changes and we use dcd_aligned_cell, the coords from the
    # xyz run are NOT the same as the coords in the dcd file, which HAS to be
    # like this. Only coords_frac can be compared, and coords after the xyz
    # run's cell has been aligned to [[x,0,0],[xy,y,0],[xz,yz,z]].  
    dir_xyz = unpack_compressed('files/cp2k/dcd/npt_xyz.tgz')
    dir_dcd = unpack_compressed('files/cp2k/dcd/npt_dcd.tgz')
    tr_xyz = io.read_cp2k_md(pj(dir_xyz, 'cp2k.out'))
    tr_dcd = io.read_cp2k_md_dcd(pj(dir_dcd, 'cp2k.out'))
    for name in ['natoms', 'nstep', 'timestep', 'symbols']:
        assert getattr(tr_xyz,name) == getattr(tr_dcd, name)
    assert tr_xyz.timestep == 1.0
    assert tr_xyz.natoms == 57
    assert tr_xyz.nstep == 16
    
    # coords are 32bit float in dcd files (single prec, so coords_frac can only
    # be accurate to that precision, which ~1e-8). cryst_const is double
    # precision in the dcd file, so atol can be lower
    assert np.allclose(tr_xyz.coords_frac, tr_dcd.coords_frac, rtol=0,
                       atol=1.5e-7)
    assert np.allclose(tr_xyz.cryst_const, tr_dcd.cryst_const, rtol=0,
                       atol=7e-10)
    assert not np.allclose(tr_xyz.coords, tr_dcd.coords, rtol=0,
                           atol=5e-6)
    assert not np.allclose(tr_xyz.cell, tr_dcd.cell, rtol=0,
                           atol=7e-10)

    # align xyz cell, now cell and coords are the same
    tr_xyz.coords = None; tr_xyz.cell=None; tr_xyz.set_all()
    
    assert np.allclose(tr_xyz.coords_frac, tr_dcd.coords_frac, rtol=0,
                       atol=1.5e-7)
    assert np.allclose(tr_xyz.cryst_const, tr_dcd.cryst_const, rtol=0,
                       atol=7e-10)
    assert np.allclose(tr_xyz.coords, tr_dcd.coords, rtol=0,
                       atol=5e-6)
    assert np.allclose(tr_xyz.cell, tr_dcd.cell, rtol=0,
                       atol=7e-10)
コード例 #12
0
ファイル: test_pdos.py プロジェクト: elcorto/pwtools
def test_pdos():
    filename = tools.unpack_compressed('files/pw.md.out.gz', prefix=__file__)
    pp = parse.PwMDOutputFile(filename=filename)
    traj = pp.get_traj()

    # timestep dt
    # -----------
    # Only needed in pd.*_pdos(), not in pd.velocity(). Here is why:
    #
    # vacf_pdos, direct_pdos:
    # If we compute the *normalized* VCAF, then dt is a factor: 
    #       <v_x(0) v_x(t)> = 1/dt^2 <dx(0) dx(t)> 
    # which cancels in the normalization. dt is not needed in the velocity
    # calculation, hence not 
    #   V=velocity(coords, dt=dt) 
    # only
    #   V=velocity(coords).
       
    V = traj.velocity # Ang / fs
    mass = traj.mass # amu
    dt = traj.timestep # fs
    timeaxis = traj.timeaxis
    assert np.allclose(150.0, dt * constants.fs / constants.tryd) # dt=150 Rydberg time units
    fd, dd = pd.direct_pdos(V, m=mass, dt=dt, npad=1, tonext=False)
    fv, dv = pd.vacf_pdos(V, m=mass, dt=dt, mirr=True)

    np.testing.assert_array_almost_equal(fd, fv, err_msg="freq not equal")
    np.testing.assert_array_almost_equal(dd, dv, err_msg="dos not equal")
    
    assert np.allclose(fd, np.loadtxt('files/ref_test_pdos/fd.txt.gz'))
    assert np.allclose(fv, np.loadtxt('files/ref_test_pdos/fv.txt.gz'))
    assert np.allclose(dd, np.loadtxt('files/ref_test_pdos/dd.txt.gz'))
    assert np.allclose(dv, np.loadtxt('files/ref_test_pdos/dv.txt.gz'))

    df = fd[1] - fd[0]
    print "Nyquist freq: %e" %(0.5/dt)
    print "df: %e:" %df
    print "timestep: %f fs = %f tryd" %(dt, dt * constants.fs / constants.tryd)
    print "timestep pw.out: %f tryd" %(pp.timestep)
    
    # API
    fd, dd, ffd, fdd, si = pd.direct_pdos(V, m=mass, dt=dt, full_out=True)
    fv, dv, ffv, fdv, si, vacf, fft_vacf = pd.vacf_pdos(V, m=mass, dt=dt,
                                                        mirr=True, full_out=True)

    # Test padding for speed.
    fd, dd, ffd, fdd, si = pd.direct_pdos(V, m=mass, dt=dt, npad=1, tonext=True, \
                           full_out=True)
    assert len(fd) == len(dd)
    assert len(ffd) == len(fdd)
    # If `tonext` is used, full fft array lengths must be a power of two.
    assert len(ffd) >= 2*V.shape[timeaxis] - 1
    assert np.log2(len(ffd)) % 1.0 == 0.0
コード例 #13
0
def test_pdos():
    filename = tools.unpack_compressed('files/pw.md.out.gz', prefix=__file__)
    pp = parse.PwMDOutputFile(filename=filename)
    traj = pp.get_traj()

    # timestep dt
    # -----------
    # Only needed in pd.*_pdos(), not in pd.velocity(). Here is why:
    #
    # vacf_pdos, direct_pdos:
    # If we compute the *normalized* VCAF, then dt is a factor: 
    #       <v_x(0) v_x(t)> = 1/dt^2 <dx(0) dx(t)> 
    # which cancels in the normalization. dt is not needed in the velocity
    # calculation, hence not 
    #   V=velocity(coords, dt=dt) 
    # only
    #   V=velocity(coords).
       
    V = traj.velocity # Ang / fs
    mass = traj.mass # amu
    dt = traj.timestep # fs
    timeaxis = traj.timeaxis
    assert np.allclose(150.0, dt * constants.fs / constants.tryd) # dt=150 Rydberg time units
    fd, dd = pd.direct_pdos(V, m=mass, dt=dt, npad=1, tonext=False)
    fv, dv = pd.vacf_pdos(V, m=mass, dt=dt, mirr=True)

    np.testing.assert_array_almost_equal(fd, fv, err_msg="freq not equal")
    np.testing.assert_array_almost_equal(dd, dv, err_msg="dos not equal")
    
    assert np.allclose(fd, np.loadtxt('files/ref_test_pdos/fd.txt.gz'))
    assert np.allclose(fv, np.loadtxt('files/ref_test_pdos/fv.txt.gz'))
    assert np.allclose(dd, np.loadtxt('files/ref_test_pdos/dd.txt.gz'))
    assert np.allclose(dv, np.loadtxt('files/ref_test_pdos/dv.txt.gz'))

    df = fd[1] - fd[0]
    print("Nyquist freq: %e" %(0.5/dt))
    print("df: %e:" %df)
    print("timestep: %f fs = %f tryd" %(dt, dt * constants.fs / constants.tryd))
    print("timestep pw.out: %f tryd" %(pp.timestep))
    
    # API
    fd, dd, ffd, fdd, si = pd.direct_pdos(V, m=mass, dt=dt, full_out=True)
    fv, dv, ffv, fdv, si, vacf, fft_vacf = pd.vacf_pdos(V, m=mass, dt=dt,
                                                        mirr=True, full_out=True)

    # Test padding for speed.
    fd, dd, ffd, fdd, si = pd.direct_pdos(V, m=mass, dt=dt, npad=1, tonext=True, \
                           full_out=True)
    assert len(fd) == len(dd)
    assert len(ffd) == len(fdd)
    # If `tonext` is used, full fft array lengths must be a power of two.
    assert len(ffd) >= 2*V.shape[timeaxis] - 1
    assert np.log2(len(ffd)) % 1.0 == 0.0
コード例 #14
0
ファイル: test_save_object.py プロジェクト: elcorto/pwtools
def test_save_object():
    filename = tools.unpack_compressed('files/pw.md.out.gz', prefix=__file__)
    dumpfile = os.path.join(testdir, 'pw.md.pk')

    c = PwMDOutputFile(filename=filename)
    print ">>> parsing ..."
    c.parse()
    print ">>> ... done"

    print ">>> saving %s ..." %dumpfile
    c.dump(dumpfile)
    print ">>> ... done"

    print ">>> loading ..."
    c2 = PwMDOutputFile()
    c2.load(dumpfile)
    print ">>> ... done"

    print ">>> checking equalness of attrs in loaded object ..."
    known_fails = {'fd': 'closed/uninitialized file',
                   'cont': 'container object'}
    arr_t = type(np.array([1]))
    dict_t = type({})
    for attr in c.__dict__.iterkeys():
        c_val = getattr(c, attr)
        c2_val = getattr(c2, attr)
        dotest = True
        for name, string in known_fails.iteritems():
            if name == attr:
                print "known fail: %s: %s: %s" %(name, string, attr)
                dotest = False
        if dotest:
            print "testing:", attr, type(c_val), type(c2_val)
            type_c = type(c_val)
            type_c2 = type(c2_val)
            assert type_c is type_c2, "attr: %s: types differ: %s, %s" \
                %(attr, str(type_c), str(type_c2))
            if type(c_val) is arr_t:
                assert (c_val == c2_val).all(), "fail: %s: %s, %s" \
                                                %(attr, c_val, c2_val)
            elif type(c_val) is dict_t:
                ade(c_val, c2_val)
            else:
                assert c_val == c2_val, "fail: %s: %s, %s" \
                                        %(attr, c_val, c2_val)
コード例 #15
0
ファイル: test_save_object.py プロジェクト: zari277/pwtools
def test_save_object():
    filename = tools.unpack_compressed('files/pw.md.out.gz', prefix=__file__)
    dumpfile = os.path.join(testdir, 'pw.md.pk')

    c = PwMDOutputFile(filename=filename)
    print(">>> parsing ...")
    c.parse()
    print(">>> ... done")

    print(">>> saving %s ..." %dumpfile)
    c.dump(dumpfile)
    print(">>> ... done")

    print(">>> loading ...")
    c2 = io.read_pickle(dumpfile)
    print(">>> ... done")

    print(">>> checking equalness of attrs in loaded object ...")
    known_fails = {'fd': 'closed/uninitialized file',
                   'cont': 'container object'}
    arr_t = type(np.array([1]))
    dict_t = type({})
    for attr in c.__dict__.keys():
        c_val = getattr(c, attr)
        c2_val = getattr(c2, attr)
        dotest = True
        for name, string in known_fails.items():
            if name == attr:
                print("known fail: %s: %s: %s" %(name, string, attr))
                dotest = False
        if dotest:
            print("testing:", attr, type(c_val), type(c2_val))
            type_c = type(c_val)
            type_c2 = type(c2_val)
            assert type_c is type_c2, "attr: %s: types differ: %s, %s" \
                %(attr, str(type_c), str(type_c2))
            if type(c_val) is arr_t:
                assert (c_val == c2_val).all(), "fail: %s: %s, %s" \
                                                %(attr, c_val, c2_val)
            elif type(c_val) is dict_t:
                ade(c_val, c2_val)
            else:
                assert c_val == c2_val, "fail: %s: %s, %s" \
                                        %(attr, c_val, c2_val)
コード例 #16
0
ファイル: test_pw_scf_out.py プロジェクト: zari277/pwtools
def test_pw_scf_one_atom():
    fn = unpack_compressed('files/pw.scf_one_atom.out.gz')
    pp = PwSCFOutputFile(fn)
    pp.parse()
    not_none = [\
        'coords',
        'symbols',
        'stress',
        'etot',
        'forces',
        'nstep_scf',
        'cell',
        'natoms',
        'nkpoints',
    ]
    tools.assert_attrs_not_none(pp, attr_lst=not_none)
    assert pp.forces.shape == (1, 3)
    assert pp.coords.shape == (1, 3)
    assert pp.stress.shape == (3, 3)
    assert pp.cell.shape == (3, 3)
コード例 #17
0
ファイル: test_pw_scf_out.py プロジェクト: elcorto/pwtools
def test_pw_scf_one_atom():
    fn = unpack_compressed('files/pw.scf_one_atom.out.gz')
    pp = PwSCFOutputFile(fn)
    pp.parse()
    not_none = [\
        'coords',
        'symbols',
        'stress',
        'etot',
        'forces',
        'nstep_scf',
        'cell',
        'natoms',
        'nkpoints',
    ]
    tools.assert_attrs_not_none(pp, attr_lst=not_none)
    assert pp.forces.shape == (1,3)
    assert pp.coords.shape == (1,3)
    assert pp.stress.shape == (3,3)
    assert pp.cell.shape == (3,3)
コード例 #18
0
ファイル: test_get_cont.py プロジェクト: zari277/pwtools
def test_get_cont():
    filename = tools.unpack_compressed('files/pw.md.out.gz', prefix=__file__)
    pp = parse.PwMDOutputFile(filename=filename)
    tr1 = pp.get_traj()

    # Need new parser instance, since pp.cont is already used, i.e. set_all()
    # called -> all attrs set. Also units are already applied, thus won't be
    # applied again since self.units_applied=True.
    pp = parse.PwMDOutputFile(filename=filename)
    tr2 = pp.get_traj(auto_calc=False)

    # specific for the used pw.out file, None is everything which is not parsed
    # since nothing is calculated from parsed data
    none_attrs = [
        'coords_frac',
        'cryst_const',
        'pressure',
        'velocity',
        'volume',
        'mass',
        'mass_unique',
        'nspecies',
        'ntypat',
        'order',
        'symbols_unique',
        'typat',
        'time',
        'znucl',
        'znucl_unique',
    ]

    for name in tr1.attr_lst:
        a1 = getattr(tr1, name)
        a2 = getattr(tr2, name)
        if name in none_attrs:
            assert a1 is not None, ("a1 %s is None" % name)
            assert a2 is None, ("a2 %s is not None" % name)
        else:
            tools.assert_all_types_equal(a1, a2)
コード例 #19
0
ファイル: test_cut_cpmd.py プロジェクト: zari277/pwtools
def run(dr):
    dr = dr[:-1] if dr.endswith('/') else dr
    workdir = unpack_compressed(dr + '.tgz')
    exe = os.path.join(os.path.dirname(__file__), '../../bin/cut-cpmd.sh')
    cmd = '{e} {w} 20 > {w}/cut-cpmd.log'.format(e=exe, w=workdir)
    sp.run(cmd, check=True, shell=True)
コード例 #20
0
ファイル: test_cut_cpmd.py プロジェクト: elcorto/pwtools
def run(dr, none_attrs=[]):
    dr = dr[:-1] if dr.endswith('/') else dr
    archive = dr + '.tgz'
    workdir = unpack_compressed(archive)
    common.system('../bin/cut-cpmd.sh %s 20 > %s/cut-cpmd.log' %(workdir,
        workdir))
コード例 #21
0
ファイル: test_dcd.py プロジェクト: elcorto/pwtools
def test_dcd():
    # nstep = 101
    # natoms = 16
    dir_lmp = tools.unpack_compressed('files/lammps/md-npt.tgz')
    fn_lmp = pj(dir_lmp, 'lmp.out.dcd') 

    # nstep = 16
    # natoms = 57
    dir_cp2k = tools.unpack_compressed('files/cp2k/dcd/npt_dcd.tgz')
    fn_cp2k = pj(dir_cp2k, 'PROJECT-pos-1.dcd')
    
    # read headers
    hdr_lmp = dcd.read_dcd_header(fn_lmp)
    hdr_cp2k = dcd.read_dcd_header(fn_cp2k)
    
    print ">>> comparing headers"
    for ref, dct in [(hdr_cp2k_ref, hdr_cp2k), (hdr_lmp_ref, hdr_lmp)]:
        tools.assert_dict_with_all_types_equal(ref, dct, keys=ref.keys(),
                                               strict=True)
    
    # compare data read by python (dcd.py) and fortran (dcd.f90, _dcd)
    # implementations
    # cc = cryst_const
    # co = coords
    print ">>> comparing data"
    for fn,convang,nstephdr,nstep,natoms in [(fn_lmp,True,True,101,16), 
                                             (fn_lmp,True,False,101,16),
                                             (fn_cp2k,False,False,16,57)]:
        cc_py, co_py = dcd.read_dcd_data(fn, convang=convang)
        cc_f, co_f = dcd.read_dcd_data_f(fn, convang=convang, nstephdr=nstephdr)
        print ">>> ... cryst_const"
        tools.assert_array_equal(cc_py, cc_f)
        print ">>> ... coords"
        tools.assert_array_equal(co_py, co_f)
        print ">>> ... shapes"
        assert cc_f.shape == (nstep,6)
        assert co_f.shape == (nstep,natoms,3)
        # lmp angles are around 60, cp2k around 90 degree, cosines are between
        # -1 and 1, make sure the angle conversion works
        print ">>> ... angles"
        assert (cc_py[:,3:] > 50).all()

    # compare slow and fast python versions
    # cc = cryst_const
    # co = coords
    print ">>> comparing data"
    for fn,convang,nstep,natoms in [(fn_lmp,True,101,16), 
                                    (fn_lmp,True,101,16),
                                    (fn_cp2k,False,16,57)]:
        cc_py_fast, co_py_fast = dcd.read_dcd_data(fn, convang=convang)
        cc_py_ref, co_py_ref = dcd.read_dcd_data_ref(fn, convang=convang)
        print ">>> ... cryst_const"
        tools.assert_array_equal(cc_py_fast, cc_py_ref)
        print ">>> ... coords"
        tools.assert_array_equal(co_py_fast, co_py_ref)
        print ">>> ... shapes"
        assert cc_py_ref.shape == (nstep,6)
        assert co_py_ref.shape == (nstep,natoms,3)
        # lmp angles are around 60, cp2k around 90 degree, cosines are between
        # -1 and 1, make sure the angle conversion works
        print ">>> ... angles"
        assert (cc_py_fast[:,3:] > 50).all()
コード例 #22
0
def test_dcd():
    # nstep = 101
    # natoms = 16
    dir_lmp = tools.unpack_compressed('files/lammps/md-npt.tgz')
    fn_lmp = pj(dir_lmp, 'lmp.out.dcd')

    # nstep = 16
    # natoms = 57
    dir_cp2k = tools.unpack_compressed('files/cp2k/dcd/npt_dcd.tgz')
    fn_cp2k = pj(dir_cp2k, 'PROJECT-pos-1.dcd')

    # read headers
    hdr_lmp = dcd.read_dcd_header(fn_lmp)
    hdr_cp2k = dcd.read_dcd_header(fn_cp2k)

    print(">>> comparing headers")
    for ref, dct in [(hdr_cp2k_ref, hdr_cp2k), (hdr_lmp_ref, hdr_lmp)]:
        tools.assert_dict_with_all_types_equal(ref,
                                               dct,
                                               keys=list(ref.keys()),
                                               strict=True)

    # compare data read by python (dcd.py) and fortran (dcd.f90, _dcd)
    # implementations
    # cc = cryst_const
    # co = coords
    print(">>> comparing data")
    for fn, convang, nstephdr, nstep, natoms in [
        (fn_lmp, True, True, 101, 16), (fn_lmp, True, False, 101, 16),
        (fn_cp2k, False, False, 16, 57)
    ]:
        cc_py, co_py = dcd.read_dcd_data(fn, convang=convang)
        cc_f, co_f = dcd.read_dcd_data_f(fn,
                                         convang=convang,
                                         nstephdr=nstephdr)
        print(">>> ... cryst_const")
        tools.assert_array_equal(cc_py, cc_f)
        print(">>> ... coords")
        tools.assert_array_equal(co_py, co_f)
        print(">>> ... shapes")
        assert cc_f.shape == (nstep, 6)
        assert co_f.shape == (nstep, natoms, 3)
        # lmp angles are around 60, cp2k around 90 degree, cosines are between
        # -1 and 1, make sure the angle conversion works
        print(">>> ... angles")
        assert (cc_py[:, 3:] > 50).all()

    # compare slow and fast python versions
    # cc = cryst_const
    # co = coords
    print(">>> comparing data")
    for fn, convang, nstep, natoms in [(fn_lmp, True, 101, 16),
                                       (fn_lmp, True, 101, 16),
                                       (fn_cp2k, False, 16, 57)]:
        cc_py_fast, co_py_fast = dcd.read_dcd_data(fn, convang=convang)
        cc_py_ref, co_py_ref = dcd.read_dcd_data_ref(fn, convang=convang)
        print(">>> ... cryst_const")
        tools.assert_array_equal(cc_py_fast, cc_py_ref)
        print(">>> ... coords")
        tools.assert_array_equal(co_py_fast, co_py_ref)
        print(">>> ... shapes")
        assert cc_py_ref.shape == (nstep, 6)
        assert co_py_ref.shape == (nstep, natoms, 3)
        # lmp angles are around 60, cp2k around 90 degree, cosines are between
        # -1 and 1, make sure the angle conversion works
        print(">>> ... angles")
        assert (cc_py_fast[:, 3:] > 50).all()
コード例 #23
0
def test_return_3d_if_no_cell_unit():
    filename = tools.unpack_compressed('files/pw.vc_relax_no_cell_unit.out.gz',
                                       prefix=__file__)
    pp = PwMDOutputFile(filename=filename)
    pp.parse()
    assert np.allclose(pp.cell, _cell*pp.get_alat())