Beispiel #1
0
def test_cpmd_write_format():
    Mol = Molecule()
    Mol.setCellDim(1, fmt='angstrom')
    Mol.setVec(((5, 0, 0), (0, 5, 0), (0, 0, 5)))
    Mol.newAtom('Na', (0, 0, 0), fmt='crystal')
    Mol.newAtom('Cl', (0.5, 0.5, 0.5), fmt='crystal')
    p = newParam('cpmd')
    p["&INFO"] = "comment\n"
    p["&CPMD"] = " MOLECULAR DYNAMICS CP\n RESTART "\
        "WAVEFUNCTION COORDINATES LATEST\n"
    fmts = ['bohr', 'angstrom', 'crystal', 'alat']
    head = "&INFO\n"\
           "comment\n"\
           "&END\n"\
           "&CPMD\n"\
           " MOLECULAR DYNAMICS CP\n RESTART "\
           "WAVEFUNCTION COORDINATES LATEST\n"\
           "&END\n"\
           "&SYSTEM\n"
    body = ["  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.uspp736.pbe BINARY\n" "  LMAX=F\n" "  1\n"
            "   0.0000  0.0000  0.0000\n"
            "*Cl.uspp736.pbe BINARY\n" "  LMAX=F\n" "  1\n"
            "   4.7243  4.7243  4.7243\n",
            "  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.uspp736.pbe BINARY\n" "  LMAX=F\n" "  1\n"
            "   0.0000  0.0000  0.0000\n"
            "*Cl.uspp736.pbe BINARY\n" "  LMAX=F\n" "  1\n"
            "   2.5000  2.5000  2.5000\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.uspp736.pbe BINARY\n" "  LMAX=F\n" "  1\n"
            "   0.0000  0.0000  0.0000\n"
            "*Cl.uspp736.pbe BINARY\n" "  LMAX=F\n" "  1\n"
            "   0.5000  0.5000  0.5000\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.uspp736.pbe BINARY\n" "  LMAX=F\n" "  1\n"
            "   0.0000  0.0000  0.0000\n"
            "*Cl.uspp736.pbe BINARY\n" "  LMAX=F\n" "  1\n"
            "   0.5000  0.5000  0.5000\n"]
    tail = "ISOTOPE\n"\
           "22.99\n"\
           "35.453\n"\
           "&END\n"
    for i in range(len(body)):
        target = head + body[i] + tail
        Mol.setFmt(fmts[i])
        f = StringIO()
        cpmd.writer(Mol, f, p)
        assert f.getvalue() == target
Beispiel #2
0
def test_lmp_write_skew():
    Mol = Molecule()
    Mol.setFmt('angstrom')
    Mol.setCellDim(1)
    Mol.setVec(((5, 0, 0), (1, 5, 0), (2, 3, 5)))
    Mol.newAtom('Na', (0, 0, 0))
    p = newParam('lmp')
    f = StringIO()
    lammpsData.writer(Mol, f, p)
    print(f.getvalue())
    target = "\n"\
             "1 atoms\n"\
             "1 atom types\n"\
             "\n"\
             " 0.0000  5.0000 xlo xhi\n"\
             " 0.0000  5.0000 ylo yhi\n"\
             " 0.0000  5.0000 zlo zhi\n"\
             " 1.0000  2.0000  3.0000 xy xz yz\n"\
             "\n"\
             "Masses\n"\
             "\n"\
             "1 22.9900 #Na\n"\
             "\n"\
             "Atoms # atomic\n"\
             "\n"\
             "1 1  0.0000  0.0000  0.0000\n"\
             "\n"
    assert f.getvalue() == target
    Mol.setVec(((5, 3, 2), (0, 5, 1), (0, 0, 5)))
    try:
        lammpsData.writer(Mol, f, p)
    except ValueError:
        assert True
    except:
        assert False
    else:
        assert False
Beispiel #3
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))))))
Beispiel #4
0
def test_cpmd_write_kpoints_constraints():
    Mol = Molecule()
    Mol.newAtom('Na', (0, 0, 0), fix=[True])
    Mol.newAtom('Na', (1, 1, 1), fix=[True, True, True])
    p = newParam('cpmd')
    p["&ATOMS"] = "CONSTRAINTS\n"\
                  "FIX COM\n"\
                  "END CONSTRAINTS\n"
    head = "&CPMD\n"\
           "&END\n"\
           "&SYSTEM\n"\
           "  CELL VECTORS\n"\
           "   1.0000  0.0000  0.0000\n"\
           "   0.0000  1.0000  0.0000\n"\
           "   0.0000  0.0000  1.0000\n"
    tail = "&END\n"\
           "&ATOMS\n"\
           "*Na.uspp736.pbe BINARY\n"\
           "  LMAX=F\n"\
           "  2\n"\
           "   0.0000  0.0000  0.0000\n"\
           "   1.0000  1.0000  1.0000\n"\
           "CONSTRAINTS\n"\
           "FIX ATOMS\n"\
           "1\n"\
           "    2\n"\
           "FIX COORDINATES\n"\
           "1\n"\
           "1  0 1 1\n"\
           "\n"\
           "FIX COM\n"\
           "END CONSTRAINTS\n"\
           "ISOTOPE\n"\
           "22.99\n"\
           "&END\n"

    def assertKpoint():
        f = StringIO()
        cpmd.writer(Mol, f, p)
        f = f.getvalue()
        assert f == target
    Mol.setKpoints('active', 'gamma')
    target = head + tail
    assertKpoint()
    Mol.setKpoints('active', 'mpg')
    Mol.setKpoints('mpg', ('2', '0', '0', '0', '0', '0'))
    target = head +\
        "  KPOINTS MONKHORST-PACK\n  2    0    0   \n" +\
        tail
    assertKpoint()
    Mol.setKpoints('mpg', ('2', '0', '0', '0', '0', '0.5'))
    target = head +\
        "  KPOINTS MONKHORST-PACK SHIFT=0    0    0.5 \n" +\
        "  2    0    0   \n" +\
        tail
    assertKpoint()
    Mol.setKpoints('active', 'discrete')
    Mol.setKpoints('discrete',
                   [['0.0', '0.0', '0.0', '0.75'],
                    ['0.5', '0.5', '0.5', '0.25']])
    Mol.setKpoints('options', {'crystal': False, 'bands': False})
    target = head +\
        "  KPOINTS\n  2\n  0.0  0.0  0.0  0.75\n  0.5  0.5  0.5  0.25\n" +\
        tail
    assertKpoint()
    Mol.setKpoints('options', {'crystal': True, 'bands': False})
    target = head +\
        "  KPOINTS SCALED\n  2\n  0.0  0.0  0.0  0.75\n"\
        "  0.5  0.5  0.5  0.25\n" +\
        tail
    assertKpoint()
    Mol.setKpoints('discrete',
                   [['0.0', '0.0', '0.0', '2'],
                    ['0.5', '0.5', '0.5', '0']])
    Mol.setKpoints('options', {'crystal': False, 'bands': True})
    target = head +\
        "  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" +\
        tail
    assertKpoint()
    Mol.setKpoints('options', {'crystal': True, 'bands': True})
    target = head +\
        "  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" +\
        tail
    assertKpoint()

    Mol.newAtom('Na', (2, 1, 1), fix=[True, True, True])
    Mol.newAtom('Na', (3, 1, 1), fix=[True, True, True])
    Mol.newAtom('Na', (4, 1, 1), fix=[True, True, True])
    Mol.newAtom('Na', (5, 1, 1), fix=[True, True, True])
    Mol.newAtom('Na', (6, 1, 1), fix=[True, True, True])
    Mol.newAtom('Na', (7, 1, 1), fix=[True, True, True])
    Mol.newAtom('Na', (8, 1, 1), fix=[True, True, True])
    Mol.newAtom('Na', (9, 1, 1), fix=[True, True, True])
    Mol.newAtom('Na', (1, 2, 1), fix=[True, True, True])
    Mol.newAtom('Na', (1, 3, 1), fix=[True, True, True])
    Mol.setKpoints('active', 'gamma')
    tail2 = "&END\n"\
            "&ATOMS\n"\
            "*Na.uspp736.pbe BINARY\n"\
            "  LMAX=F\n"\
            "  12\n"\
            "   0.0000  0.0000  0.0000\n"\
            "   1.0000  1.0000  1.0000\n"\
            "   2.0000  1.0000  1.0000\n"\
            "   3.0000  1.0000  1.0000\n"\
            "   4.0000  1.0000  1.0000\n"\
            "   5.0000  1.0000  1.0000\n"\
            "   6.0000  1.0000  1.0000\n"\
            "   7.0000  1.0000  1.0000\n"\
            "   8.0000  1.0000  1.0000\n"\
            "   9.0000  1.0000  1.0000\n"\
            "   1.0000  2.0000  1.0000\n"\
            "   1.0000  3.0000  1.0000\n"\
            "CONSTRAINTS\n"\
            "FIX ATOMS\n"\
            "11\n"\
            "    2    3    4    5    6    7    8    9   10   11\n"\
            "   12\n"\
            "FIX COORDINATES\n"\
            "1\n"\
            "1  0 1 1\n"\
            "END CONSTRAINTS\n"\
            "ISOTOPE\n"\
            "22.99\n"\
            "&END\n"
    target = head + tail2
    f = StringIO()
    cpmd.writer(Mol, f, newParam('cpmd'))
    for i in range(len(target.split('\n'))):
        print(f.getvalue().split('\n')[i], target.split('\n')[i])
        assert f.getvalue().split('\n')[i] == target.split('\n')[i]
    assert f.getvalue() == target
Beispiel #5
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]
Beispiel #6
0
def test_pwi_write_calc():
    calcs = ["'scf'",
             "'relax'",
             "'vc-relax'"]
    adnl = ["",
            "&ions\n ion_dynamics='bfgs'\n/\n\n",
            "&ions\n ion_dynamics='bfgs'\n/\n\n"
            "&cell\n cell_dynamics='bfgs'\n/\n\n"]
    head = "&control\n calculation="
    body = "\n/\n\n"\
           "&system\n"\
           " nat=2\n"\
           " ntyp=1\n"\
           " celldm(1)=2.0\n"\
           " ibrav=0\n"\
           " ecutwfc=30.0\n"\
           "/\n"\
           "\n"\
           "&electrons\n"\
           " diagonalization='david'\n"\
           " conv_thr=1.0e-8\n"\
           "/\n"\
           "\n"
    tail = "ATOMIC_SPECIES\n"\
           "C    12.0107   C.uspp736.pbe.UPF\n"\
           "\n"\
           "ATOMIC_POSITIONS crystal\n"\
           "C     0.00000  0.00000  0.00000 1 0 1\n"\
           "C     0.50000  0.50000  0.50000\n"\
           "\n"\
           "K_POINTS automatic\n"\
           "2    0    0    0    0    0   \n"\
           "\n"\
           "CELL_PARAMETERS\n"\
           " 1.00000  2.00000  0.00000\n"\
           " 0.00000  5.00000  6.00000\n"\
           " 0.00000  8.00000  9.00000\n"
    Mol = Molecule()
    Mol.setFmt('crystal')
    Mol.setCellDim(2)
    Mol.setVec(((1, 2, 0), (0, 5, 6), (0, 8, 9)))
    Mol.newAtom('C', (0, 0, 0), fix=[False, True])
    Mol.newAtom('C', [0.5, 0.5, 0.5], fmt='crystal')
    Mol.setKpoints('active', 'mpg')
    Mol.setKpoints('mpg', ('2', '0', '0', '0', '0', '0'))

    def failWrite(p):
        try:
            pwInput.writer(Mol, f, p)
        except KeyError:
            return True
        else:
            return False

    for c in range(3):
        for a in range(3):
            Param = newParam('pwi')
            Param['&control']['calculation'] = calcs[c]
            Param['&electrons']['diagonalization'] = "'david'"
            Param['&electrons']['conv_thr'] = "1.0e-8"
            if a > 0:
                Param['&ions'] = {'ion_dynamics': "'bfgs'"}
            if a > 1:
                Param['&cell'] = {'cell_dynamics': "'bfgs'"}
            f = StringIO()
            if a < c:
                failWrite(Param)
            else:
                pwInput.writer(Mol, f, Param)
                target = head + calcs[c] + body + adnl[a] + tail
                assert f.getvalue() == target
    # default to scf when nothing present:
    Param = newParam('pwi')
    Param['&electrons']['diagonalization'] = "'david'"
    Param['&electrons']['conv_thr'] = "1.0e-8"
    f = StringIO()
    pwInput.writer(Mol, f, Param)
    target = "&control" + body + tail
    assert f.getvalue() == target
Beispiel #7
0
def test_lmp_write_proper():
    Mol = Molecule()
    Mol.setFmt('angstrom')
    Mol.setCellDim(1)
    Mol.setVec(((5, 0, 0), (0, 5, 0), (0, 0, 5)))
    Mol.newAtom('Na', (0.0, 0.0, 0.0), charge=1.)
    Mol.newAtom('Na', (2.5, 2.5, 0.0), charge=1.)
    Mol.newAtom('Na', (0.0, 2.5, 2.5), charge=1.)
    Mol.newAtom('Na', (2.5, 0.0, 2.5), charge=1.)
    Mol.newAtom('Cl', (0.0, 2.5, 0.0), charge=-1.)
    Mol.newAtom('Cl', (2.5, 0.0, 0.0), charge=-1.)
    Mol.newAtom('Cl', (0.0, 0.0, 2.5), charge=-1.)
    Mol.newAtom('Cl', (2.5, 2.5, 2.5), charge=-1.)
    p = newParam('lmp')
    p['atom_style'] = 'full'
    p['bonds'] = True
    p['angles'] = True
    p['dihedrals'] = True
    p['impropers'] = True
    head = "\n"\
           "8 atoms\n"\
           "2 atom types\n"\
           "12 bonds\n"\
           "1 bond types\n"\
           "#1 Cl Na\n"\
           "24 angles\n"\
           "2 angle types\n"\
           "#1 Cl Na Cl\n"\
           "#2 Na Cl Na\n"\
           "48 dihedrals\n"\
           "1 dihedral types\n"\
           "#1 Cl Na Cl Na\n"\
           "8 impropers\n"\
           "2 improper types\n"\
           "#1 Cl Na Na Na\n"\
           "#2 Na Cl Cl Cl\n"\
           "\n"\
           " 0.0000  5.0000 xlo xhi\n"\
           " 0.0000  5.0000 ylo yhi\n"\
           " 0.0000  5.0000 zlo zhi\n"\
           "\n"\
           "Masses\n"\
           "\n"\
           "1 22.9900 #Na\n"\
           "2 35.4530 #Cl\n"\
           "\n"
    tail = "\nBonds\n\n"\
           "1 1 1 5\n2 1 1 6\n3 1 1 7\n4 1 2 5\n5 1 2 6\n"\
           "6 1 2 8\n7 1 3 5\n8 1 3 7\n9 1 3 8\n10 1 4 6\n"\
           "11 1 4 7\n12 1 4 8\n"\
           "\nAngles\n\n"\
           "1 1 5 1 6\n2 1 5 1 7\n3 2 1 5 2\n4 2 1 5 3\n"\
           "5 1 6 1 7\n6 2 1 6 2\n7 2 1 6 4\n8 2 1 7 3\n"\
           "9 2 1 7 4\n10 1 5 2 6\n11 1 5 2 8\n12 2 2 5 3\n"\
           "13 1 6 2 8\n14 2 2 6 4\n15 2 2 8 3\n16 2 2 8 4\n"\
           "17 1 5 3 7\n18 1 5 3 8\n19 1 7 3 8\n20 2 3 7 4\n"\
           "21 2 3 8 4\n22 1 6 4 7\n23 1 6 4 8\n24 1 7 4 8\n"\
           "\nDihedrals\n\n"\
           "1 1 6 1 5 2\n2 1 6 1 5 3\n3 1 5 1 6 2\n4 1 5 1 6 4\n"\
           "5 1 7 1 5 2\n6 1 7 1 5 3\n7 1 5 1 7 3\n8 1 5 1 7 4\n"\
           "9 1 1 5 2 6\n10 1 1 5 2 8\n11 1 1 5 3 7\n12 1 1 5 3 8\n"\
           "13 1 7 1 6 2\n14 1 7 1 6 4\n15 1 6 1 7 3\n16 1 6 1 7 4\n"\
           "17 1 1 6 2 5\n18 1 1 6 2 8\n19 1 1 6 4 7\n20 1 1 6 4 8\n"\
           "21 1 1 7 3 5\n22 1 1 7 3 8\n23 1 1 7 4 6\n24 1 1 7 4 8\n"\
           "25 1 6 2 5 3\n26 1 5 2 6 4\n27 1 8 2 5 3\n28 1 5 2 8 3\n"\
           "29 1 5 2 8 4\n30 1 2 5 3 7\n31 1 2 5 3 8\n32 1 8 2 6 4\n"\
           "33 1 6 2 8 3\n34 1 6 2 8 4\n35 1 2 6 4 7\n36 1 2 6 4 8\n"\
           "37 1 2 8 3 5\n38 1 2 8 3 7\n39 1 2 8 4 6\n40 1 2 8 4 7\n"\
           "41 1 5 3 7 4\n42 1 5 3 8 4\n43 1 8 3 7 4\n44 1 7 3 8 4\n"\
           "45 1 3 7 4 6\n46 1 3 7 4 8\n47 1 3 8 4 6\n48 1 3 8 4 7\n"\
           "\nImpropers\n\n"\
           "1 2 1 5 6 7\n2 2 2 5 6 8\n3 2 3 5 7 8\n4 2 4 6 7 8\n"\
           "5 1 5 1 2 3\n6 1 6 1 2 4\n7 1 7 1 3 4\n8 1 8 2 3 4\n"\
           "\n"
    atoms = "Atoms # full\n"\
            "\n"\
            "1 1 1  1.0000  0.0000  0.0000  0.0000\n"\
            "2 1 1  1.0000  2.5000  2.5000  0.0000\n"\
            "3 1 1  1.0000  0.0000  2.5000  2.5000\n"\
            "4 1 1  1.0000  2.5000  0.0000  2.5000\n"\
            "5 1 2 -1.0000  0.0000  2.5000  0.0000\n"\
            "6 1 2 -1.0000  2.5000  0.0000  0.0000\n"\
            "7 1 2 -1.0000  0.0000  0.0000  2.5000\n"\
            "8 1 2 -1.0000  2.5000  2.5000  2.5000\n"
    f = StringIO()
    lammpsData.writer(Mol, f, p)
    target = head + atoms + tail
    assert f.getvalue() == target