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 __init__(self, ibrav = 1,a = 1. ,b = 1.,c = 1., cBC = 0.,cAC = 0. ,cAB = 0., base = None, lattice = None, qeInput = None ): self.formatString = '%# .8f %# .8f %# .8f' self._qeInput = qeInput #self._qeInput = None self._type = 'celldm' # Lattice container class, used for lattice operations self.__primitiveLattice = Lattice() # Lattice vectors in bohr or angstrom: self._base = None # initialize the lattice if there is enough information if ibrav > 0 and base != None: self.setLatticeFromQEVectors(ibrav, base) else: self.setLattice(ibrav ,a ,b , c, cBC ,cAC ,cAB, base) # copy constructor: if isinstance(ibrav, QELattice) or lattice != None: if lattice.ibrav > 0: self.setLattice( ibrav = lattice.ibrav, a = lattice.a, \ b = lattice.b, c = lattice.c, cBC = lattice.cBC, cAC = lattice.cAC,\ cAB = lattice.cAB) else: self.setLattice( ibrav = lattice.ibrav, a = lattice.a, \ base = lattice.base ) # copy input: from pwinput import PWInput self._qeInput = PWInput() self._qeInput.readString( lattice._qeInput.toString() )
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 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 test_placeInLattice(self): """check Structure.placeInLattice() -- conversion of coordinates """ stru = self.stru new_lattice = Lattice(.5, .5, .5, 90, 90, 60) stru.placeInLattice(new_lattice) a0 = stru[0] self.assertListAlmostEqual(a0.xyz, 3*[0.0]) a1 = stru[1] self.assertListAlmostEqual(a1.xyz, [2.0, 0.0, 2.0])
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 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 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 __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 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 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 OrthorhombicPeriodicUniverse(vecLengths): from matter.Lattice import Lattice return Lattice(base=[[vecLengths[0],0,0], [0,vecLengths[1],0], [0,0,vecLengths[2]]])
from dsaw.db import connect db = connect(db='postgres:///test') db.autocommit(True) from dsaw.model.visitors.OrmManager import OrmManager orm = OrmManager(db) from matter.Lattice import Lattice l1 = Lattice() l1.id = 'l1' orm.save(l1) orm.destroyAllTables()
def _setReducedStructureFromMatterStructure(self, structure, ibrav, massList=[], psList=[]): """ structure - matter.Structure object ibrav - Lattice index psList - list of strings with potential names matterStructure object will be modified with reduced atomic positions """ import copy matterLattice = copy.deepcopy(structure.lattice) # there is a big problem with what Nikolay is doing because he is initializing QELattice with abcalbega which # leaves room for errors in how the basis vectors are chosen compared to the old lattice a = matterLattice.a b = matterLattice.b c = matterLattice.c cAB = cosd(matterLattice.gamma) cBC = cosd(matterLattice.alpha) cAC = cosd(matterLattice.beta) qeLattice = QELattice(ibrav = ibrav, a = a, b = b, c = c, cBC = cBC, \ cAC = cAC, cAB = cAB) #what he should do is initialize the vectors of QELattice with the vectors of matterLattice # qeLattice._qeInput = self._qeInput self.lattice = qeLattice # make a deep copy: reducedStructure = Structure(atoms=structure) reducedStructure.placeInLattice(Lattice(base=qeLattice.matter().base)) # collect atoms that are at equivalent position to some previous atom duplicates = set([ a1 for i0, a0 in enumerate(reducedStructure) for a1 in reducedStructure[i0 + 1:] if a0.symbol == a1.symbol and equalPositions(a0.xyz, a1.xyz, eps=1e-4) ]) # Filter out duplicate atoms. Use slice assignment so that # reducedStructure is not replaced with a list. reducedStructure[:] = [ a for a in reducedStructure if not a in duplicates ] atomNames = [] for a in reducedStructure: if a.symbol not in atomNames: atomNames.append(a.symbol) atomicSpecies = {} for i, elem in enumerate(atomNames): if len(massList) - 1 < i: mass = 0 else: mass = massList[i] if len(psList) - 1 < i: ps = '' else: ps = psList[i] atomicSpecies[elem] = (mass, ps) self[:] = [] # convert to bohr units self.lattice.setLattice(ibrav, self.lattice.a*1.889725989, \ self.lattice.b*1.889725989, self.lattice.c*1.889725989) for atom in reducedStructure: self.addNewAtom(atype = atom.symbol, xyz = atom.xyz, \ mass = atomicSpecies[atom.symbol][0], \ potential = atomicSpecies[atom.symbol][1],\ lattice = self.lattice, optConstraint = [])
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()
def ParallelepipedicPeriodicUniverse(vecs): from matter.Lattice import Lattice return Lattice(base=vecs)
from properties import * import numpy from matter.Lattice import Lattice cartesian_lattice = Lattice() class AtomPropertyCurator(type): """meta class for Atom class to collect all properties and set up some class constants. It establishes: - Atom class's docstring - a list of names of properties - the list of setable attributes, "_setable", (to be used in method __setattr__ of Atom class). NOTE: Brandon doesn't like this third one...user-scripters should be able to set whatever they want...why limit them? Alex read this note :) """ def __init__(AtomClass, name, bases, dict): from matter import METACLASS_CTOR_NEEDS_TYPE if METACLASS_CTOR_NEEDS_TYPE: type.__init__(AtomClass, name, bases, dict) else: type.__init__(name, bases, dict) isotopeNumberProperties, inferredProperties, states = AtomPropertyCurator.collectProperties( AtomClass ) properties = isotopeNumberProperties + inferredProperties + states AtomClass.propertyNames = [ p.name for p in properties ] propStr = '\n'.join( [ " %s: %s" % (p.name, p.doc) for p in properties ] ) #global doc