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
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
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"