예제 #1
0
def test_cpmd_parse_format():
    name = 'cpmd_format'
    head = ["&INFO\n",
            "comment\n",
            "&END\n",
            "\n",
            "!comment\n",
            "&CPMD\n",
            " MOLECULAR DYNAMICS CP\n",
            " RESTART WAVEFUNCTION COORDINATES LATEST\n",
            "&END",
            "&SYSTEM\n",
            "CUTOFF\n",
            " 25.0\n",
            "TESR\n",
            " 2\n"]
    tails = [["ANGSTROM\n",
              "CELL VECTORS\n", "5.0000 0.0000 0.0000\n",
              "0.0000 5.0000 0.0000\n", "0.0000 0.0000 5.0000\n",
              "&END\n",
              "&ATOMS\n",
              "*Na.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.00000  0.00000\n", " 2.50000  2.50000  0.00000\n",
              " 0.00000  2.50000  2.50000\n", " 2.50000  0.00000  2.50000\n",
              "*Cl.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  2.50000  0.00000\n", " 2.50000  0.00000  0.00000\n",
              " 0.00000  0.00000  2.50000\n", " 2.50000  2.50000  2.50000\n",
              "&END\n"],
             ["CELL VECTORS\n", "9.4486 0.0000 0.0000\n",
              "0.0000 9.4486 0.0000\n", "0.0000 0.0000 9.4486\n",
              "&END\n",
              "&ATOMS\n",
              "*Na.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.00000  0.00000\n", " 4.72432  4.72432  0.00000\n",
              " 0.00000  4.72432  4.72432\n", " 4.72432  0.00000  4.72432\n",
              "*Cl.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  4.72432  0.00000\n", " 4.72432  0.00000  0.00000\n",
              " 0.00000  0.00000  4.72432\n", " 4.72432  4.72432  4.72432\n",
              "&END\n"],
             ["SCALE CARTESIAN\n",
              "CELL VECTORS\n", "9.4486 0.0000 0.0000\n",
              "0.0000 9.4486 0.0000\n", "0.0000 0.0000 9.4486\n",
              "&END\n",
              "&ATOMS\n",
              "*Na.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.00000  0.00000\n", " 0.50000  0.50000  0.00000\n",
              " 0.00000  0.50000  0.50000\n", " 0.50000  0.00000  0.50000\n",
              "*Cl.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.50000  0.00000\n", " 0.50000  0.00000  0.00000\n",
              " 0.00000  0.00000  0.50000\n", " 0.50000  0.50000  0.50000\n",
              "&END\n"],
             ["SCALE\n",
              "CELL VECTORS\n", "9.4486 0.0000 0.0000\n",
              "0.0000 9.4486 0.0000\n", "0.0000 0.0000 9.4486\n",
              "&END\n",
              "&ATOMS\n",
              "*Na.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.00000  0.00000\n", " 0.50000  0.50000  0.00000\n",
              " 0.00000  0.50000  0.50000\n", " 0.50000  0.00000  0.50000\n",
              "*Cl.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.50000  0.00000\n", " 0.50000  0.00000  0.00000\n",
              " 0.00000  0.00000  0.50000\n", " 0.50000  0.50000  0.50000\n",
              "&END\n"],
             ["SCALE S=0.5\n",
              "CELL VECTORS\n", "9.4486 0.0000 0.0000\n",
              "0.0000 9.4486 0.0000\n", "0.0000 0.0000 9.4486\n",
              "&END\n",
              "&ATOMS\n",
              "*Na.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.00000  0.00000\n", " 0.25000  0.25000  0.00000\n",
              " 0.00000  0.25000  0.25000\n", " 0.25000  0.00000  0.25000\n",
              "*Cl.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.25000  0.00000\n", " 0.25000  0.00000  0.00000\n",
              " 0.00000  0.00000  0.25000\n", " 0.25000  0.25000  0.25000\n",
              "&END\n"],
             ["SCALE SX=0.5\n",
              "CELL VECTORS\n", "9.4486 0.0000 0.0000\n",
              "0.0000 9.4486 0.0000\n", "0.0000 0.0000 9.4486\n",
              "&END\n",
              "&ATOMS\n",
              "*Na.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.00000  0.00000\n", " 0.25000  0.50000  0.00000\n",
              " 0.00000  0.50000  0.50000\n", " 0.25000  0.00000  0.50000\n",
              "*Cl.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.50000  0.00000\n", " 0.25000  0.00000  0.00000\n",
              " 0.00000  0.00000  0.50000\n", " 0.25000  0.50000  0.50000\n",
              "&END\n"],
             ["SCALE SX=0.5 SY=0.5 SZ=2\n",
              "CELL VECTORS\n", "9.4486 0.0000 0.0000\n",
              "0.0000 9.4486 0.0000\n", "0.0000 0.0000 9.4486\n",
              "&END\n",
              "&ATOMS\n",
              "*Na.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.00000  0.00000\n", " 0.25000  0.25000  0.00000\n",
              " 0.00000  0.25000  1.00000\n", " 0.25000  0.00000  1.00000\n",
              "*Cl.uspp.pbe BINARY\n", " LMAX=F\n", " 4\n",
              " 0.00000  0.25000  0.00000\n", " 0.25000  0.00000  0.00000\n",
              " 0.00000  0.00000  1.00000\n", " 0.25000  0.25000  1.00000\n",
              "&END\n"]]
    formats = ['angstrom', 'bohr', 'alat', 'crystal',
               'crystal', 'crystal', 'crystal']
    targetp = newParam('cpmd')
    targetp["name"] = name
    targetp["&INFO"] = "comment\n"
    targetp["&CPMD"] = " MOLECULAR DYNAMICS CP\n RESTART "\
        "WAVEFUNCTION COORDINATES LATEST\n"
    targetp["&SYSTEM"] = "CUTOFF\n 25.0\nTESR\n 2\n"
    for f in range(len(formats)):
        Mol, p = cpmd.parser(name, head + tails[f])
        assert p == targetp
        assert len(Mol) == 1
        assert Mol.name == name
        assert Mol.nat == 8
        assert Mol.ntyp == 2
        assert Mol.getTypes() == ["Na", "Cl"]
        assert Mol.getFmt() == formats[f]
        assert Mol.getKpoints('active') == 'gamma'
        assert vec_equal(Mol.getVec() * Mol.getCellDim(fmt='angstrom'),
                         ((5, 0, 0), (0, 5, 0), (0, 0, 5)))
        assert list(map(len, Mol.getBonds(1.1))) == [12, 4, 4, 0, 4, 0, 0, 0]
        assert all(map(lambda x: atom_equal(*x), zip(
            Mol.getAtoms(fmt='angstrom'),
            (('Na', (0, 0, 0)), ('Na', (2.5, 2.5, 0)), ('Na', (0, 2.5, 2.5)),
             ('Na', (2.5, 0, 2.5)), ('Cl', (0, 2.5, 0)), ('Cl', (2.5, 0, 0)),
             ('Cl', (0, 0, 2.5)), ('Cl', (2.5, 2.5, 2.5))))))
예제 #2
0
def test_cpmd_parse_symmetry():
    name = 'cpmd_symmetry'
    symm = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '12', '14',
            "ISOLATED", "CUBIC", "FACE CENTERED CUBIC", "FCC",
            "BODY CENTERED CUBIC", "BCC", "HEXAGONAL", "TRIGONAL",
            "RHOMBOHEDRAL", "TETRAGONAL", "BODY CENTERED TETRAGONAL",
            "BCT", "ORTHORHOMBIC", "MONOCLINIC", "TRICLINIC", '14', '14', '14']
    cell = [["CELL\n", "5 1 1 0 0 0\n"],
            ["CELL\n", "5 0 0 0 0 0\n"],
            ["CELL\n", "5 0 0 0 0 0\n"],
            ["CELL\n", "5 0 0 0 0 0\n"],
            ["CELL\n", "5 0 1.5 0 0 0\n"],
            ["CELL\n", "5 0 0 0.5 0 0\n"],
            ["CELL\n", "5 0 1.5 0 0 0\n"],
            ["CELL\n", "5 0 1.5 0 0 0\n"],
            ["CELL\n", "5 1.25 1.5 0 0 0\n"],
            ["CELL\n", "5 1.25 1.5 0.5 0 0\n"],
            ["CELL\n", "5 1.25 1.5 0.25 0.75 0.5\n"],
            ["CELL\n", "5 1 1 0 0 0\n"],
            ["CELL\n", "5 0 0 0 0 0\n"],
            ["CELL\n", "5 0 0 0 0 0\n"],
            ["CELL\n", "5 0 0 0 0 0\n"],
            ["CELL\n", "5 0 0 0 0 0\n"],
            ["CELL\n", "5 0 0 0 0 0\n"],
            ["CELL\n", "5 0 1.5 0 0 0\n"],
            ["CELL\n", "5 0 0 0.5 0 0\n"],
            ["CELL\n", "5 0 0 0.5 0 0\n"],
            ["CELL\n", "5 0 1.5 0 0 0\n"],
            ["CELL\n", "5 0 1.5 0 0 0\n"],
            ["CELL\n", "5 0 1.5 0 0 0\n"],
            ["CELL\n", "5 1.25 1.5 0 0 0\n"],
            ["CELL\n", "5 1.25 1.5 0.5 0 0\n"],
            ["CELL\n", "5 1.25 1.5 0.25 0.75 0.5\n"],
            ["CELL ABSOLUTE\n", "5 6.25 7.5 0.25 0.75 0.5\n"],
            ["CELL DEGREE\n", "5 1.25 1.5 75.5225 41.4096 60\n"],
            ["CELL ABSOLUTE DEGREE\n", "5 6.25 7.5 75.5225 41.4096 60\n"]]
    head = ["&INFO\n",
            "comment\n",
            "&END\n",
            "\n",
            "!comment\n",
            "&CPMD\n",
            " MOLECULAR DYNAMICS CP\n",
            " RESTART WAVEFUNCTION COORDINATES LATEST\n",
            "&END",
            "&SYSTEM\n",
            "CUTOFF\n",
            " 25.0\n",
            "TESR\n",
            " 2\n",
            "ANGSTROM\n",
            "SYMMETRY\n"]
    tail = ["&END\n",
            "&ATOMS\n",
            "*Na.uspp.pbe BINARY\n",
            " LMAX=F\n",
            " 4\n",
            " 0.00000  0.00000  0.00000\n",
            " 0.50000  0.50000  0.00000\n",
            " 0.00000  0.50000  0.50000\n",
            " 0.50000  0.00000  0.50000\n",
            "*Cl.uspp.pbe BINARY\n",
            " LMAX=F\n",
            " 4\n",
            " 0.00000  0.50000  0.00000\n",
            " 0.50000  0.00000  0.00000\n",
            " 0.00000  0.00000  0.50000\n",
            " 0.50000  0.50000  0.50000\n",
            "&END\n"]
    vectarget = [((1, 0, 0), (0, 1, 0), (0, 0, 1)),
                 ((1, 0, 0), (0, 1, 0), (0, 0, 1)),
                 ((-0.5, 0, 0.5), (0, 0.5, 0.5), (-0.5, 0.5, 0)),
                 ((0.5, 0.5, 0.5), (-0.5, 0.5, 0.5), (-0.5, -0.5, 0.5)),
                 ((1, 0, 0), (-0.5, np.sqrt(3) * 0.5, 0), (0, 0, 1.5)),
                 ((0.5, -0.288675, 0.81650), (0, 0.57735, 0.81650),
                  (-0.5, -0.288675, 0.81650)),
                 ((1, 0, 0), (0, 1, 0), (0, 0, 1.5)),
                 ((0.5, -0.5, 0.75), (0.5, 0.5, 0.75), (-0.5, -0.5, 0.75)),
                 ((1, 0, 0), (0, 1.25, 0), (0, 0, 1.5)),
                 ((1, 0, 0), (0.625, 1.08253, 0), (0, 0, 1.5)),
                 ((1, 0, 0), (0.625, 1.082532, 0),
                  (1.125, -0.216506, 0.96825)),
                 ((1, 0, 0), (0, 1, 0), (0, 0, 1)),
                 ((1, 0, 0), (0, 1, 0), (0, 0, 1)),
                 ((-0.5, 0, 0.5), (0, 0.5, 0.5), (-0.5, 0.5, 0)),
                 ((-0.5, 0, 0.5), (0, 0.5, 0.5), (-0.5, 0.5, 0)),
                 ((0.5, 0.5, 0.5), (-0.5, 0.5, 0.5), (-0.5, -0.5, 0.5)),
                 ((0.5, 0.5, 0.5), (-0.5, 0.5, 0.5), (-0.5, -0.5, 0.5)),
                 ((1, 0, 0), (-0.5, np.sqrt(3) * 0.5, 0), (0, 0, 1.5)),
                 ((0.5, -0.288675, 0.81650), (0, 0.57735, 0.81650),
                  (-0.5, -0.288675, 0.81650)),
                 ((0.5, -0.288675, 0.81650), (0, 0.57735, 0.81650),
                  (-0.5, -0.288675, 0.81650)),
                 ((1, 0, 0), (0, 1, 0), (0, 0, 1.5)),
                 ((0.5, -0.5, 0.75), (0.5, 0.5, 0.75), (-0.5, -0.5, 0.75)),
                 ((0.5, -0.5, 0.75), (0.5, 0.5, 0.75), (-0.5, -0.5, 0.75)),
                 ((1, 0, 0), (0, 1.25, 0), (0, 0, 1.5)),
                 ((1, 0, 0), (0.625, 1.08253, 0), (0, 0, 1.5)),
                 ((1, 0, 0), (0.625, 1.082532, 0),
                  (1.125, -0.216506, 0.96825)),
                 ((1, 0, 0), (0.625, 1.082532, 0),
                  (1.125, -0.216506, 0.96825)),
                 ((1, 0, 0), (0.625, 1.082532, 0),
                  (1.125, -0.216506, 0.96825)),
                 ((1, 0, 0), (0.625, 1.082532, 0),
                  (1.125, -0.216506, 0.96825))]
    for i in range(len(symm)):
        Mol, _ = cpmd.parser(name, head + [symm[i]] + cell[i] + tail)
        assert float_equal(Mol.getCellDim(fmt='angstrom'), 5)
        assert vec_equal(Mol.getVec(), vectarget[i])
예제 #3
0
def test_cpmd_parse_constraints():
    name = 'cpmd_constraints'
    head = ["&INFO\n",
            "comment\n",
            "&END\n",
            "\n",
            "!comment\n",
            "&CPMD\n",
            " MOLECULAR DYNAMICS CP\n",
            " RESTART WAVEFUNCTION COORDINATES LATEST\n",
            "&END",
            "&SYSTEM\n",
            "CUTOFF\n",
            " 25.0\n",
            "TESR\n",
            " 2\n",
            "SCALE\n",
            "CELL VECTORS\n",
            "9.4486 0.0000 0.0000\n",
            "0.0000 9.4486 0.0000\n",
            "0.0000 0.0000 9.4486\n",
            "&END\n",
            "&ATOMS\n",
            "*Na.uspp.pbe BINARY\n",
            " LMAX=F\n",
            " 1\n",
            " 0.00000  0.00000  0.00000\n",
            "*Na_MT_PBE.psp KLEINMAN-BYLANDER\n",
            " LMAX=P\n",
            " 1\n",
            " 0.50000  0.50000  0.00000\n",
            "*Na.uspp.pbe BINARY\n",
            " LMAX=F\n",
            " 2\n",
            " 0.00000  0.50000  0.00000\n",
            " 0.50000  0.00000  0.00000\n",
            "ISOTOPE\n",
            " 21.994\n",
            " 22.989\n",
            " 23.990\n",
            "CONSTRAINTS\n"]
    cons = [[],
            ["FIX ALL\n"],
            ["FIX QM\n"],
            ["FIX MM\n"],
            ["FIX PPTY\n", "3\n"],
            ["FIX PPTY SEQUENCE\n", "3 1 3\n"],
            ["FIX ELEMENT\n", "11\n"],
            ["FIX ELEMENT SEQUENCE\n", "11 1 3\n"],
            ["FIX SEQUENCE\n", "1 3\n"],
            ["FIX ATOMS\n", "2\n", "1 3\n"],
            ["FIX COORDINATES\n", "3\n",
             "1 0 1 1\n", "2 1 0 1\n", "3 1 1 0\n"],
            ["FIX COORDINATES\n", "4\n",
             "1 0 0 1\n", "2 0 1 0\n", "3 1 0 0\n", "4 0 0 0\n"],
            ]
    F = [False, False, False]
    X = [True, False, False]
    Y = [False, True, False]
    Z = [False, False, True]
    XY = [True, True, False]
    XZ = [True, False, True]
    YZ = [False, True, True]
    A = [True, True, True]
    fixtarget = [[F, F, F, F], [A, A, A, A], [A, A, A, A], [F, F, F, F],
                 [F, F, A, A], [F, F, A, F], [A, A, A, A], [A, A, A, F],
                 [A, A, A, F], [A, F, A, F], [X, Y, Z, F], [XY, XZ, YZ, A],
                 ]
    for i in range(len(cons)):
        Mol, _ = cpmd.parser(name,
                             head + cons[i] + ["END CONSTRAINTS\n", "&END\n"])
        assert Mol.nat == 4
        assert Mol.ntyp == 3
        assert Mol.getTypes() == ['Na', 'Na1', 'Na2']
        assert Mol.pse['Na']['m'] == 21.994
        assert Mol.pse['Na1']['m'] == 22.989
        assert Mol.pse['Na2']['m'] == 23.990
        assert list(map(lambda x: x[-1], Mol.getAtoms(fix=True))) ==\
            fixtarget[i]
예제 #4
0
def test_cpmd_parse_kpoints():
    name = 'cpmd_kpoints'
    head = ["&INFO\n",
            "comment\n",
            "&END\n",
            "\n",
            "!comment\n",
            "&CPMD\n",
            " MOLECULAR DYNAMICS CP\n",
            " RESTART WAVEFUNCTION COORDINATES LATEST\n",
            "&END",
            "&SYSTEM\n"]
    tail = ["CUTOFF\n",
            " 25.0\n",
            "TESR\n",
            " 2\n",
            "SCALE\n",
            "CELL VECTORS\n",
            "9.4486 0.0000 0.0000\n",
            "0.0000 9.4486 0.0000\n",
            "0.0000 0.0000 9.4486\n",
            "&END\n",
            "&ATOMS\n",
            "*Na.uspp.pbe BINARY\n",
            " LMAX=F\n",
            " 4\n",
            " 0.00000  0.00000  0.00000\n",
            " 0.50000  0.50000  0.00000\n",
            " 0.00000  0.50000  0.50000\n",
            " 0.50000  0.00000  0.50000\n",
            "*Cl.uspp.pbe BINARY\n",
            " LMAX=F\n",
            " 4\n",
            " 0.00000  0.50000  0.00000\n",
            " 0.50000  0.00000  0.00000\n",
            " 0.00000  0.00000  0.50000\n",
            " 0.50000  0.50000  0.50000\n",
            "&END\n"]
    ksys = [[],
            ["KPOINTS MONKHORST-PACK\n", "2 0 0\n"],
            ["KPOINTS MONKHORST-PACK SHIFT=0 0 0\n", "2 0 0\n"],
            ["KPOINTS\n", "2\n", "0.0 0.0 0.0 2\n", "0.5 0.5 0.5 0\n"],
            ["KPOINTS SCALED\n", "2\n", "0.0 0.0 0.0 2\n", "0.5 0.5 0.5 0\n"],
            ["KPOINTS BANDS\n", "2 0.0 0.0 0.0 0.5 0.5 0.5\n",
             "0 0 0 0 0 0 0\n"],
            ["KPOINTS SCALED BANDS\n", "2 0.0 0.0 0.0 0.5 0.5 0.5\n",
             "0 0 0 0 0 0 0\n"]]
    kfmt = ['gamma', 'mpg', 'mpg', 'discrete',
            'discrete', 'discrete', 'discrete']
    opttarget = [{'crystal': False, 'bands': False},
                 {'crystal': True, 'bands': False},
                 {'crystal': False, 'bands': True},
                 {'crystal': True, 'bands': True}]
    targetp = newParam('cpmd')
    targetp["name"] = name
    targetp["&INFO"] = "comment\n"
    targetp["&CPMD"] = " MOLECULAR DYNAMICS CP\n RESTART "\
        "WAVEFUNCTION COORDINATES LATEST\n"
    targetp["&SYSTEM"] = "CUTOFF\n 25.0\nTESR\n 2\n"
    for k in range(len(kfmt)):
        Mol, p = cpmd.parser(name, head + ksys[k] + tail)
        assert p == targetp
        assert len(Mol) == 1
        assert Mol.name == name
        assert Mol.nat == 8
        assert Mol.ntyp == 2
        assert Mol.getTypes() == ["Na", "Cl"]
        assert Mol.getFmt() == 'crystal'
        assert vec_equal(Mol.getVec() * Mol.getCellDim(fmt='angstrom'),
                         ((5, 0, 0), (0, 5, 0), (0, 0, 5)))
        assert list(map(len, Mol.getBonds(1.1))) == [12, 4, 4, 0, 4, 0, 0, 0]
        assert all(map(lambda x: atom_equal(*x), zip(
            Mol.getAtoms(fmt='angstrom'),
            (('Na', (0, 0, 0)), ('Na', (2.5, 2.5, 0)), ('Na', (0, 2.5, 2.5)),
             ('Na', (2.5, 0, 2.5)), ('Cl', (0, 2.5, 0)), ('Cl', (2.5, 0, 0)),
             ('Cl', (0, 0, 2.5)), ('Cl', (2.5, 2.5, 2.5))))))
        assert Mol.getKpoints('active') == kfmt[k]
        if Mol.getKpoints('active') == 'mpg':
            assert Mol.getKpoints('mpg') == ['2', '0', '0', '0', '0', '0']
        elif Mol.getKpoints('active') == 'discrete':
            assert Mol.getKpoints('discrete') ==\
                [['0.0', '0.0', '0.0', '2'],
                 ['0.5', '0.5', '0.5', '0']]
            assert Mol.getKpoints('options') == opttarget[k - 3]