Пример #1
0
def test_atoms_bohr():
    Mol = Molecule()
    Mol.setCellDim(2)
    Mol.newAtom()
    Mol.newAtom('H', (1, 1, 1), 1, [True, False], True)
    assert Mol.nat == 2
    assert Mol.ntyp == 2
    assert Mol.getTypes() == ['H', 'C']
    assert Mol.getCellDim() == 2
    assert atom_equal(Mol.getAtom(0, charge=True, fix=True, hidden=True),
                      ['C', (0, 0, 0), 0., [False, False, False], False])
    assert atom_equal(Mol.getAtom(1, charge=True, fix=True, hidden=True),
                      ['H', (1, 1, 1), 1., [True, False, False], True])
    assert list(map(len, Mol.getBonds(1.1))) == [1, 1, 1, 1, 1, 1, 1, 1]
    Mol.delAtom(1)
    assert Mol.nat == 1
    assert Mol.getTypes() == ['C']
    Mol.newAtoms(2)
    assert Mol.getTypes() == ['X', 'C']
    Mol.setAtom(1, 'O', (0.5, 0.5, 0.5), 2, [False, True], False)
    Mol.setAtom(2, 'U', (1, 1, 1), 2, [True], False)
    assert atom_equal(Mol.getAtom(1, charge=True, fix=True, hidden=True),
                      ['O', (0.5, 0.5, 0.5), 2., [False, True, False], False])
    assert atom_equal(Mol.getAtom(2, charge=True, fix=True, hidden=True),
                      ['U', (1, 1, 1), 2., [True, False, False], False])
    assert Mol.getTypes() == ['C', 'O', 'U']
    target = (['C', (0, 0, 0), 0., [False, False, False], False],
              ['O', (0.5, 0.5, 0.5), 2., [False, True, False], False],
              ['U', (1, 1, 1), 2., [True, False, False], False])
    for a, t in zip(Mol.getAtoms(True, True, True), target):
        assert atom_equal(a, t)
Пример #2
0
def test_modify():
    Mol = Molecule()
    assert Mol.getUndo() == None
    Mol.undo()
    Mol.setVec(((5, 0, 0), (0, 5, 0), (0, 0, 5)))
    Mol.newAtom('C', (0.5, 0.5, 0.5), fmt='crystal')
    assert vec_equal(Mol.getVec(), ((5, 0, 0), (0, 5, 0), (0, 0, 5)))
    assert Mol.nat == 1
    Mol.mult(2, 1, 1)
    assert vec_equal(Mol.getVec(), ((10, 0, 0), (0, 5, 0), (0, 0, 5)))
    assert Mol.nat == 2
    Mol.mult(1, 2, 2)
    assert vec_equal(Mol.getVec(), ((10, 0, 0), (0, 10, 0), (0, 0, 10)))
    assert Mol.nat == 8
    Mol.setVec(((5, 0, 0), (0, 5, 0), (0, 0, 5)))
    Mol.crop()
    assert Mol.nat == 1
    Mol.mult(2, 2, 2)
    assert vec_equal(Mol.getVec(), ((10, 0, 0), (0, 10, 0), (0, 0, 10)))
    assert Mol.nat == 8
    Mol.setVec(((7, 0, 0), (0, 7, 0), (0, 0, 7)))
    Mol.wrap()
    assert Mol.nat == 8
    assert list(map(len, Mol.getBonds(1.1))) == [24, 0, 0, 0, 0, 0, 0, 0]
    assert Mol.getUndo() == 'wrap atoms'
    Mol.undo()
    assert list(map(len, Mol.getBonds(1.1))) == [0, 4, 4, 4, 4, 4, 4, 0]
    Mol.wrap()
    Mol.reshape(((14, 7, 0), (0, 7, 0), (0, 0, 7)))
    assert list(map(len, Mol.getBonds(1.1))) == [38, 0, 10, 0, 0, 0, 0, 0]
    assert vec_equal(Mol.getVec(), ((14, 7, 0), (0, 7, 0), (0, 0, 7)))
    Mol.undo()
    Mol.setVec(((5, 0, 0), (0, 5, 0), (0, 0, 5)))
    assert atom_equal(Mol.getAtom(1, fmt="crystal"), ('C', (0.1, 0.5, 0.5)))
    Mol.align(1, 'x')
    assert vec_equal(Mol.getVec(), ((0, -5, 0), (5, 0, 0), (0, 0, 5)))
    Mol.undo()
    Mol.align(1, 'y')
    assert vec_equal(Mol.getVec(), ((5, 0, 0), (0, 5, 0), (0, 0, 5)))
    Mol.align(1, 'z')
    assert vec_equal(Mol.getVec(), ((5, 0, 0), (0, 0, 5), (0, -5, 0)))
    Mol.undo()
    try:
        Mol.align(0, 1)
    except ValueError:
        assert True
    except:
        assert False, "Wrong error"
    else:
        assert False, "Error missing"
Пример #3
0
def test_molecule():
    Mol = Molecule(name="Test Mol", steps=0)
    assert Mol.name == "Test Mol"
    assert len(Mol) == 0
    Mol.newStep()
    assert len(Mol) == 1
    Mol.newAtom('C', (1, 1, 1))
    assert Mol.nat == 1
    assert atom_equal(Mol.getAtom(0, fmt='crystal'), ['C', (1, 1, 1)])
    Mol.copyStep()
    assert len(Mol) == 2
    for s in Mol.steps:
        assert s.nat == 1
        assert s.getCellDim() == 1
    assert Mol.curStep == 1
    Mol.changeStep(0)
    assert Mol.curStep == 0
    Mol.setCellDimAll(1, fmt='angstrom', scale=True)
    for s in Mol.steps:
        assert float_equal(s.getCellDim(fmt='angstrom'), 1)
        assert vec_equal(s.getVec(), ((1, 0, 0), (0, 1, 0), (0, 0, 1)))
        assert atom_equal(s.getAtom(0, fmt='angstrom'), ['C', (1, 1, 1)])
    Mol.setVecAll(((2, 0, 0), (0, 2, 0), (0, 0, 2)), scale=True)
    for s in Mol.steps:
        assert float_equal(s.getCellDim(fmt='angstrom'), 1)
        assert vec_equal(s.getVec(), ((2, 0, 0), (0, 2, 0), (0, 0, 2)))
        assert atom_equal(s.getAtom(0, fmt='angstrom'), ['C', (2, 2, 2)])
    Mol.setVecAll(((1, 0, 0), (0, 1, 0), (0, 0, 1)))
    for s in Mol.steps:
        assert float_equal(s.getCellDim(fmt='angstrom'), 1)
        assert vec_equal(s.getVec(), ((1, 0, 0), (0, 1, 0), (0, 0, 1)))
        assert atom_equal(s.getAtom(0, fmt='crystal'), ['C', (2, 2, 2)])
    assert Mol.getKpoints('active') == 'gamma'
    assert Mol.getKpoints('mpg') == ['1', '1', '1', '0', '0', '0']
    assert Mol.getKpoints('discrete') == []
    assert Mol.getKpoints('options') == {'crystal': False, 'bands': False}
    Mol.setKpoints('active', 'mpg')
    assert Mol.getKpoints('active') == 'mpg'
    Mol1 = Mol.copy()
    assert len(Mol1) == 1
    assert Mol1.name == "Copy of Test Mol"
    Mol2 = Mol.copyAll()
    assert len(Mol2) == 2
    assert Mol2.name == "Copy of Test Mol"
Пример #4
0
def test_atoms_fmt():
    Mol = Molecule()
    # standard: bohr:
    assert Mol.getFmt() == 'bohr'
    assert float_equal(Mol.getCellDim(), 1)
    assert vec_equal(Mol.getVec(), ((1, 0, 0), (0, 1, 0), (0, 0, 1)))
    Mol.newAtom('C', (1, 1, 1))
    assert atom_equal(Mol.getAtom(0), ('C', (1, 1, 1)))
    # transition to angstrom:
    Mol.setFmt("angstrom", scale=True)
    assert Mol.getFmt() == 'angstrom'
    Mol.setCellDim(1)
    assert float_equal(Mol.getCellDim(), 1)
    assert atom_equal(Mol.getAtom(0, fmt="angstrom"), ('C', (1, 1, 1)))
    Mol.setCellDim(2.5, scale=True, fmt='angstrom')
    Mol.newAtom('C', (2.5, 2.5, 2.5), fmt='angstrom')
    for at in Mol.getAtoms():
        assert atom_equal(at, ('C', (2.5, 2.5, 2.5)))
    Mol.setVec(((2, 0, 0), (0, 2, 0), (0, 0, 2)), scale=True)
    assert vec_equal(Mol.getVec(), ((2, 0, 0), (0, 2, 0), (0, 0, 2)))
    Mol.newAtom('C', (5, 5, 5), fmt='angstrom')
    Mol.newAtom('C', (2, 2, 2), fmt='alat')
    Mol.newAtom('C', (1, 1, 1), fmt='crystal')
    for at in Mol.getAtoms():
        assert atom_equal(at, ('C', (5, 5, 5)))
    for at in Mol.getAtoms(fmt='alat'):
        assert atom_equal(at, ('C', (2, 2, 2)))
    for at in Mol.getAtoms(fmt='crystal'):
        assert atom_equal(at, ('C', (1, 1, 1)))
    # scale back down to bohr
    Mol.setCellDim(2.5, scale=True, fmt='bohr')
    for at in Mol.getAtoms(fmt='bohr'):
        assert atom_equal(at, ('C', (5, 5, 5)))
    Mol.setFmt('alat', scale=True)
    for at in Mol.getAtoms(fmt='bohr'):
        assert atom_equal(at, ('C', (12.5, 12.5, 12.5)))
    Mol.setFmt('crystal', scale=True)
    for at in Mol.getAtoms(fmt='bohr'):
        assert atom_equal(at, ('C', (62.5, 62.5, 62.5)))
    assert vec_equal(Mol.getCenter(), (2.5, 2.5, 2.5))
    assert vec_equal(Mol.getCenter(com=True), (62.5, 62.5, 62.5))
Пример #5
0
def test_selection():
    Mol = Molecule()
    Mol.newAtom('C', (0, 0, 0))
    Mol.addSelection([1, (0, 0, 0)])
    Mol.addSelection([1, (1, 0, 0)])
    assert Mol.getSelection() == [[1, (0, 0, 0)], [1, (1, 0, 0)]]
    Mol.addSelection([1, (1, 0, 0)])
    assert Mol.getSelection() == [[1, (0, 0, 0)]]
    Mol.delSelection()
    assert Mol.getSelection() == []
Пример #6
0
def test_scripting():
    Mol = Molecule()
    Mol.setFmt('angstrom')
    Mol.newAtom('C', (0, 0, 0))
    Mol.newAtom('O', (1, 1, 0))
    Mol.newAtom('B', (2, 2, 0))
    Mol.newAtom('U', (0, 2, 0))
    Mol.evalScript("def g all tU\n"
                   "shi g 1-3 2")
    assert atom_equal(Mol.getAtom(3), ('U', (2, 0, 0)))
    Mol.undo()
    Mol.evalScript("rot 3 90 2-0 1")
    assert atom_equal(Mol.getAtom(3), ('U', (1, 1, np.sqrt(2))))
    Mol.undo()
    Mol.evalScript("rot 3 90 2-0\n"
                   "mir 3 (1,0,0) (0,0,1,'angstrom') (1,0,0)")
    assert atom_equal(Mol.getAtom(3), ('U', (1, -1, np.sqrt(2))))
    Mol = Molecule()
    Mol.setFmt('angstrom')
    Mol.setCellDim(15)
    Mol.newAtom('C1', (0, 0, 0))
    Mol.newAtom('C1', (1, 0, 0))
    Mol.newAtom('C1', (1, 0, 0))
    Mol.newAtom('C2', (0, 0, 3))
    Mol.newAtom('C2', (1, 0, 3))
    Mol.newAtom('C2', (1, 0, 3))
    Mol.evalScript("rot [2, 5] 60 (0, 0, 1)")
    Mol.evalScript("rot 3-5 90 (1, 0, 0) 3")
    assert len(Mol.getBonds(1.1)[0]) == 6
    Mol.evalScript("sel all tC2\npar sel sel 0-2")
    atoms = Mol.getAtoms()
    assert vec_equal(atoms[0][1], atoms[3][1]-(0,0,3))
    assert vec_equal(atoms[1][1], atoms[4][1]-(0,0,3))
    assert vec_equal(atoms[2][1], atoms[5][1]-(0,0,3))
    Mol.evalScript("rot sel 45 (1, 0, 0) 3")
    Mol.evalScript("pshift 0-2 (0,0,1) sel")
    assert atom_equal(Mol.getAtom(0), ['C1', (0, np.sqrt(2)/2, -np.sqrt(2)/2)])
    assert atom_equal(Mol.getAtom(1), ['C1', (1, np.sqrt(2)/2, -np.sqrt(2)/2)])
    assert atom_equal(Mol.getAtom(2), ['C1', (0.5, (np.sqrt(3)+np.sqrt(2))/2, -np.sqrt(2)/2)])
Пример #7
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
Пример #8
0
def test_empire_write():
    target = "3\n"\
             "Hamil=PM3 calc=spt Periodic\n"\
             "O     0.0000  0.0000  0.0000\n"\
             "H     0.9572  0.0000  0.0000\n"\
             "H    -0.2400  0.9266  0.0000\n"\
             "\n"\
             "1.0000 0.0000 0.0000\n"\
             "0.0000 2.0000 0.0000\n"\
             "0.0000 0.0000 3.0000\n"
    f = StringIO()
    Mol = Molecule()
    Mol.newAtom('O', (0, 0, 0), fmt='angstrom')
    Mol.newAtom('H', (0.9572, 0, 0), fmt='angstrom')
    Mol.newAtom('H', (-0.23999, 0.926627, 0), fmt='angstrom')
    Mol.setCellDim(1, fmt='angstrom')
    Mol.setVec(((1, 0, 0), (0, 2, 0), (0, 0, 3)))
    empire.writer(Mol, f, None)
    assert f.getvalue() == target
Пример #9
0
def test_pwi_write_kpoints():
    body = "&control\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"\
           "/\n"\
           "\n"\
           "ATOMIC_SPECIES\n"\
           "C    12.0107   C.uspp736.pbe.UPF\n"\
           "\n"\
           "ATOMIC_POSITIONS alat\n"\
           "C     0.00000  0.00000  0.00000 1 0 1\n"\
           "C     0.50000  7.50000  7.50000\n"\
           "\n"
    tail = "\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"
    Param = pwInput.param['default'].copy()
    Mol = Molecule()
    Mol.setFmt('alat')
    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')

    def assertKpoint():
        f = StringIO()
        pwInput.writer(Mol, f, Param)
        assert f.getvalue() == target
    Mol.setKpoints('active', 'gamma')
    target = body + "K_POINTS gamma\n" + tail
    assertKpoint()
    Mol.setKpoints('active', 'mpg')
    Mol.setKpoints('mpg', ('2', '0', '0', '0', '0', '0'))
    target = body +\
        "K_POINTS automatic\n2    0    0    0    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 = body +\
        "K_POINTS tpiba\n2\n0.0  0.0  0.0  0.75\n0.5  0.5  0.5  0.25\n" +\
        tail
    assertKpoint()
    Mol.setKpoints('options', {'crystal': False, 'bands': True})
    target = body +\
        "K_POINTS tpiba_b\n2\n0.0  0.0  0.0  0.75\n0.5  0.5  0.5  0.25\n" +\
        tail
    assertKpoint()
    Mol.setKpoints('options', {'crystal': True, 'bands': False})
    target = body +\
        "K_POINTS crystal\n2\n0.0  0.0  0.0  0.75\n0.5  0.5  0.5  0.25\n" +\
        tail
    assertKpoint()
    Mol.setKpoints('options', {'crystal': True, 'bands': True})
    target = body +\
        "K_POINTS crystal_b\n2\n0.0  0.0  0.0  0.75\n0.5  0.5  0.5  0.25\n" +\
        tail
    assertKpoint()
Пример #10
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
Пример #11
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
Пример #12
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
Пример #13
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
Пример #14
0
def grapheneOrtho(x, y, z):
    """
    Create an orthogonal cell of graphene

    x -> x-dimension
    y -> sqrt(3)*y-dimension
    z -> interlayer distance
    """
    mol = Molecule(name="({:},{:})-ortho graphene".format(x, y))
    mol.setCellDim(Agraph)
    mol.setVec([vecX, sq3 * vecY, z * vecZ])
    mol.newAtom('C', [0, 0, 0])
    mol.newAtom('C', [0, 1. / 3., 0])
    mol.newAtom('C', [0.5, 0.5, 0])
    mol.newAtom('C', [0.5, 5. / 6., 0])
#    mol.scaleAtoms("crystal")
#    mol.setFmt("crystal")
    mol.setFmt("crystal", scale=True)
    mol.mult(x, y, 1)
    return mol
Пример #15
0
def grapheneHex(x, y, z):
    """
    Create a hexagonal cell of graphene

    x -> x-dimension
    y -> 0.5*x+0.5*sqrt(3)*y-dimension
    z -> interlayer distance
    """
    mol = Molecule(name="({:},{:})-hex graphene".format(x, y))
    mol.setCellDim(Agraph)
    mol.setVec([vecX, vecYh, z * vecZ])
    mol.newAtom('C', [1. / 3., 2. / 3., 0])
    mol.newAtom('C', [2. / 3., 1. / 3., 0])
#    mol.scaleAtoms("crystal")
#    mol.setFmt("crystal")
    mol.setFmt("crystal", scale=True)
    mol.mult(x, y, 1)
    return mol