def A(name, index, type = None): from matter.Atom import Atom #hack--sometimes 'name' contains element and sometimes 'type' if len(name)<3: return Atom(name) if len(type)<3: return Atom(type)
def setUp(self): # at1 = Atom('C', [0.333333333333333, 0.666666666666667, 0]) # at2 = Atom('C', [0.666666666666667, 0.333333333333333, 0]) at1 = Atom('C', [0, 0, 0]) at2 = Atom('C', [1, 1, 1]) self.stru = Structure([at1, at2], lattice=Lattice(1, 1, 1, 90, 90, 120)) self.places = 12
def testGetChemicalFormula(self): at1 = Atom('C', [0.333333333333333, 0.666666666666667, 0]) at2 = Atom('C', [0.666666666666667, 0.333333333333333, 0]) #at3 = Atom('H', [0, 0, 0]) stru = Structure([at1, at2], lattice=Lattice(3.8, 3.8, 5.6, 90, 90, 120)) print 'formula: ', stru.getChemicalFormula() return
def testChemicalFormulaPositionsSymbols(self): at1 = Atom('C', [0.333333333333333, 0.666666666666667, 0]) at2 = Atom('C', [0.666666666666667, 0.333333333333333, 0]) #at3 = Atom('H', [0, 0, 0]) stru = Structure( [ at1, at2], lattice=Lattice(3.8, 3.8, 5.6, 90, 90, 120) ) assert stru.getChemicalFormula()=='C_2' #self.assertListAlmostEqual(stru.xyz, [[0.33333333333333298, 0.66666666666666696, 0.0], [0.66666666666666696, 0.33333333333333298, 0.0]]) #self.assertListAlmostEqual(stru.xyz_cartn,[[1.0969655114602876, 1.9000000000000017, 0.0], [2.1939310229205784, -2.0020877317117325e-15, 0.0]]) #self.assertListAlmostEqual(stru.symbols, ['C', 'C']) #print "here's the lattice", stru.lattice.base return
def test1(self): 'Structure: property "primitive_unitcell"' lattice = Lattice(a=2, b=2, c=2, alpha=90, beta=90, gamma=90) atoms = [ Atom('Ni', (0, 0, 0)), Atom('Ni', (0, 0.5, 0.5)), Atom('Ni', (0.5, 0, 0.5)), Atom('Ni', (0.5, 0.5, 0)), ] struct = Structure(lattice=lattice, atoms=atoms, sgid=225) print struct.primitive_unitcell return
def test2a(self): 'Structure: methood "symConsistent"' lattice = Lattice(a=2, b=2, c=2, alpha=90, beta=90, gamma=90) atoms = [ Atom('Ni', (0, 0, 0)), Atom('Ni', (0, 0.5, 0.5)), Atom('Ni', (0.5, 0, 0.5)), Atom('Ni', (0.5, 0.5, 0)), ] struct = Structure(lattice=lattice, atoms=atoms, sgid=225) verdict, pos, op = struct.symConsistent() self.assert_(verdict) return
def test_al_supercell(self): """check supercell expansion for Al. """ at1 = Atom('Al', [0.0, 0.0, 0.0]) at2 = Atom('Al', [0.0, 0.5, 0.5]) at3 = Atom('Al', [0.5, 0.0, 0.5]) at4 = Atom('Al', [0.5, 0.5, 0.0]) self.stru4 = Structure( [ at1, at2, at3, at4], lattice=Lattice(4.05, 4.05, 4.05, 90, 90, 90), sgid = 225 ) al_sup = supercell(self.stru4, (3,3,3)) #print al_sup return
def test_NaI(self): """check supercell expansion for Al. """ at1 = Atom('Na', [0.0, 0.0, 0.0]) at2 = Atom('Na', [0.0, 0.5, 0.5]) at3 = Atom('Na', [0.5, 0.0, 0.5]) at4 = Atom('Na', [0.5, 0.5, 0.0]) at5 = Atom('I', [0.5, 0.5, 0.5]) at6 = Atom('I', [0.0, 0.0, 0.5]) at7 = Atom('I', [0.0, 0.5, 0.0]) at8 = Atom('I', [0.5, 0.0, 0.0]) naI = Structure( [ at1, at2, at3, at4, at5, at6, at7, at8], lattice = Lattice(6.482, 6.482, 6.482, 90, 90, 90), sgid = 225 ) lines = [] for sym,pos in zip(naI.symbols, naI.xyz_cartn): lines.append( sym+' %f %f %f' % tuple(pos) ) lines.append('\n') naI_sup = supercell(naI, (2,2,2)) for sym,pos in zip(naI_sup.symbols, naI_sup.xyz_cartn): lines.append(sym+' %f %f %f' % tuple(pos)) expected = open('expected-test_NaI-TestSuperCell').readlines() self.assertEqual(len(lines), len(expected)) for l1, l2 in zip(lines, expected): self.assertEqual(l1.strip(), l2.strip()) return
def test1(self): 'Structure: property "primitive_unitcell"' lattice = Lattice(a=2, b=2, c=2, alpha=90, beta=90, gamma=90) atoms = [ Atom('Ni', (0, 0, 0)), Atom('Ni', (0, 0.5, 0.5)), Atom('Ni', (0.5, 0, 0.5)), Atom('Ni', (0.5, 0.5, 0)), ] struct = Structure(lattice=lattice, atoms=atoms, sgid=225) pcell = struct.primitive_unitcell self.assert_(pcell) self.assertArrayEqual(pcell.base, [[-1., 0., 1.], [0., 1., 1.], [-1., 1., 0.]]) return
def test3(self): 'Structure: "primitive_unitcell"' lattice = Lattice(a=2, b=2, c=2, alpha=90, beta=90, gamma=90) atoms = [ Atom('Fe', (0, 0, 0)), Atom('Pd', (0, 0.5, 0.5)), Atom('Pd', (0.5, 0, 0.5)), Atom('Pd', (0.5, 0.5, 0)), ] struct = Structure(lattice=lattice, atoms=atoms, sgid=221) verdict, pos, op = struct.symConsistent() print verdict, pos, op self.assert_(verdict) self.assertEqual(len(struct.primitive_unitcell.atoms), 4) return
def setUp(self): # at1 = Atom('C', [0.333333333333333, 0.666666666666667, 0]) # at2 = Atom('C', [0.666666666666667, 0.333333333333333, 0]) at1 = Atom('C', [0, 0, 0]) at2 = Atom('C', [1, 1, 1]) self.stru = Structure([at1, at2], lattice=Lattice(1, 1, 1, 90, 90, 120)) ciffile = os.path.join(testdata_dir, 'PbTe.cif') self.stru2 = Structure() self.stru2.read(ciffile) ciffile = os.path.join(testdata_dir, 'graphite.cif') self.stru3 = Structure() self.stru3.read(ciffile) at1 = Atom('Al', [0.0, 0.0, 0.0]) at2 = Atom('Al', [0.0, 0.5, 0.5]) at3 = Atom('Al', [0.5, 0.0, 0.5]) at4 = Atom('Al', [0.5, 0.5, 0.0]) self.stru4 = Structure([at1, at2, at3, at4], lattice=Lattice(4.05, 4.05, 4.05, 90, 90, 90), sgid=225) self.places = 12
def __restoreFromInventory__(self, inventory): atoms = [] from matter.Atom import Atom from matter.Lattice import Lattice for symbol, pos in zip(inventory.atom_symbols, inventory.atom_positions): atoms.append(Atom(symbol, pos)) self.__init__( atoms=atoms, lattice=Lattice(base=inventory.lattice_base), sgid=inventory.spacegroup_num, description=inventory.short_description, ) #self.primitive_unitcell = inventory.primitive_unitcell return
def test_naI_supercell(self): """check supercell expansion for Al. """ at1 = Atom('Na', [0.0, 0.0, 0.0]) at2 = Atom('Na', [0.0, 0.5, 0.5]) at3 = Atom('Na', [0.5, 0.0, 0.5]) at4 = Atom('Na', [0.5, 0.5, 0.0]) at5 = Atom('I', [0.5, 0.5, 0.5]) at6 = Atom('I', [0.0, 0.0, 0.5]) at7 = Atom('I', [0.0, 0.5, 0.0]) at8 = Atom('I', [0.5, 0.0, 0.0]) naI = Structure([at1, at2, at3, at4, at5, at6, at7, at8], lattice=Lattice(6.482, 6.482, 6.482, 90, 90, 90), sgid=225) for sym, pos in zip(naI.symbols, naI.xyz_cartn): print sym + ' %f %f %f' % tuple(pos) print naI_sup = supercell(naI, (2, 2, 2)) for sym, pos in zip(naI_sup.symbols, naI_sup.xyz_cartn): print sym + ' %f %f %f' % tuple(pos)
def getAtomsInOneUnitCell(matter): "get atoms in one unit cell, including atoms in the faces" from matter.Atom import Atom from matter.SymmetryUtilities import expandPosition # list of atoms to return ret = [] # cache['H'] are a list of positions that are already # include in result atom list cache = {} # sg = matter.sg for atom in matter: symbol = atom.symbol # all equivalent but unique positions for this atom positions, pops, pmult = expandPosition(sg, atom.xyz) # get the cache for this type of atom cache1 = cache.get(symbol) if cache1 is None: cache1 = cache[symbol] = [] # loop over all positions for position in positions: position = tuple(position) if position in cache1: continue # add new position to cache, and the new atom to the result list # cache1.append(position) # ret.append(Atom(symbol, position)) # also see if the position is at boundary, if so, add all # boundary atoms positions_at_boundary = getPositionsAtBoundary(position) for pos in positions_at_boundary: cache1.append(pos) ret.append(Atom(symbol, pos)) continue continue continue return ret
from dsaw.db import connect db = connect(db='postgres:///test', echo=True) db.autocommit(True) from dsaw.model.visitors.OrmManager import OrmManager orm = OrmManager(db) from matter.Atom import Atom from matter.Lattice import Lattice from matter.orm.BigStructure import Structure at1 = Atom('C', [0.333333333333333, 0.666666666666667, 0]) at2 = Atom('C', [0.666666666666667, 0.333333333333333, 0]) hexag = Lattice(2.456, 2.456, 6.696, 90, 90, 120) graphite = Structure([at1, at2], lattice=hexag, sgid=194) graphite.id = 'graphite' print graphite #lattice=Lattice(a=2.456, b=2.456, c=6.696, alpha=90, beta=90, gamma=120) #C 0.333333 0.666667 0.000000 1.0000 #C 0.666667 0.333333 0.000000 1.0000 from matter.expansion import supercell graphite_sheet = supercell(graphite, (10, 10, 1)) graphite_sheet.id = 'sheet' print graphite_sheet.getChemicalFormula() #C200 orm.save(graphite_sheet) #orm.destroyAllTables()