def reduce(self, ibrav=None): """ Reduces a structure instance with nonprimitive lattice ( i.e. solves for equivalent atomic positions) according to specified lattice type (ibrav). Each ibrav number corresponds to a specific primitive lattice (see QE documentation). """ ib = self.lattice.ibrav if ibrav != None: ib = ibrav a = self.lattice.diffpy().a b = self.lattice.diffpy().b c = self.lattice.diffpy().c cAB = cosd(self.lattice.diffpy().gamma) cBC = cosd(self.lattice.diffpy().alpha) cAC = cosd(self.lattice.diffpy().beta) if ib > 0: qeLattice = QELattice(ibrav = ib, a = a, b = b, c = c, cBC = cBC, \ cAC = cAC, cAB = cAB) else: qeLattice = QELattice(ibrav=ib, base=self.lattice.base) qeLattice._qeInput = self._qeInput reducedStructure = QEStructure(self) reducedStructure.placeInLattice(qeLattice) # 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.element == a1.element 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. self.lattice = qeLattice self[:] = [a for a in reducedStructure if not a in duplicates] self._qeInput.structure = self return
def reduce(self, ibrav = None): """ Reduces a structure instance with nonprimitive lattice ( i.e. solves for equivalent atomic positions) according to specified lattice type (ibrav). Each ibrav number corresponds to a specific primitive lattice (see QE documentation). """ ib = self.lattice.ibrav if ibrav != None: ib = ibrav a = self.lattice.diffpy().a b = self.lattice.diffpy().b c = self.lattice.diffpy().c cAB = cosd(self.lattice.diffpy().gamma) cBC = cosd(self.lattice.diffpy().alpha) cAC = cosd(self.lattice.diffpy().beta) if ib > 0: qeLattice = QELattice(ibrav = ib, a = a, b = b, c = c, cBC = cBC, \ cAC = cAC, cAB = cAB) else: qeLattice = QELattice(ibrav = ib, base = self.lattice.base) qeLattice._qeInput = self._qeInput reducedStructure = QEStructure(self) reducedStructure.placeInLattice( qeLattice ) # 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.element == a1.element 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. self.lattice = qeLattice self[:] = [a for a in reducedStructure if not a in duplicates] self._qeInput.structure = self return
def _setReducedStructureFromDiffpyStructure(self, structure, ibrav, massList=[], psList=[]): """ structure - diffpy.Structure object ibrav - Lattice index psList - list of strings with potential names diffpyStructure object will be modified with reduced atomic positions """ import copy diffpyLattice = copy.deepcopy(structure.lattice) a = diffpyLattice.a b = diffpyLattice.b c = diffpyLattice.c cAB = cosd(diffpyLattice.gamma) cBC = cosd(diffpyLattice.alpha) cAC = cosd(diffpyLattice.beta) qeLattice = QELattice(ibrav = ibrav, a = a, b = b, c = c, cBC = cBC, \ cAC = cAC, cAB = cAB) qeLattice._qeInput = self._qeInput self.lattice = qeLattice # make a deep copy: reducedStructure = Structure(atoms=structure) reducedStructure.placeInLattice(Lattice(base=qeLattice.diffpy().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 self._element(a0) == self._element(a1) 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 self._element(a) not in atomNames: atomNames.append(self._element(a)) 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: elem = self._element(atom) self.addNewAtom(atype = elem, xyz = atom.xyz, \ mass = atomicSpecies[elem][0], \ potential = atomicSpecies[elem][1],\ lattice = self.lattice, optConstraint = [])
def _setReducedStructureFromDiffpyStructure(self, structure, ibrav, massList = [], psList = []): """ structure - diffpy.Structure object ibrav - Lattice index psList - list of strings with potential names diffpyStructure object will be modified with reduced atomic positions """ import copy diffpyLattice = copy.deepcopy(structure.lattice) a = diffpyLattice.a b = diffpyLattice.b c = diffpyLattice.c cAB = cosd(diffpyLattice.gamma) cBC = cosd(diffpyLattice.alpha) cAC = cosd(diffpyLattice.beta) qeLattice = QELattice(ibrav = ibrav, a = a, b = b, c = c, cBC = cBC, \ cAC = cAC, cAB = cAB) qeLattice._qeInput = self._qeInput self.lattice = qeLattice # make a deep copy: reducedStructure = Structure(atoms = structure) reducedStructure.placeInLattice(Lattice(base=qeLattice.diffpy().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 self._element(a0) == self._element(a1) 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 self._element(a) not in atomNames: atomNames.append(self._element(a)) 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: elem = self._element(atom) self.addNewAtom(atype = elem, xyz = atom.xyz, \ mass = atomicSpecies[elem][0], \ potential = atomicSpecies[elem][1],\ lattice = self.lattice, optConstraint = [])
def setLatticeFromQEVectors(self, ibrav, vectors): """ Will extract conventional lattice parameters from primitive vectors. 'vectors' - is a list with primitive vectors (in QE notation), including lattice parameters. For example from PWSCF output""" from numpy import dot # default values: a = b = c = 1.0 cBC = cAC = cAB = 0.0 v = numpy.array(vectors, dtype = float) if ibrav == 0: raise NotImplementedError # sc simple cubic: if ibrav == 1: a = v[0,0] if ibrav == 2: a = b = c = sqrt( 2.0*dot(v[0,:],v[0,:]) ) if ibrav == 3: a = b = c = 2.0*sqrt( dot(v[0,:],v[0,:])/3.0) if ibrav == 4: a = b = sqrt( dot(v[0,:],v[0,:])) c = sqrt( dot(v[2,:],v[2,:])) cAB = cosd(120.0) if ibrav == 5: a = b = c = sqrt( dot(v[0,:],v[0,:])) cBC = cAC = cAB = dot(v[0,:],v[2,:])/a**2 if ibrav == 6: a = b = sqrt( dot(v[0,:],v[0,:])) c = sqrt( dot(v[2,:],v[2,:])) if ibrav == 7: a = b = v[1,0] - v[2,0] c = v[1,2] + v[2,2] if ibrav == 8: a = v[0,0] b = v[1,1] c = v[2,2] if ibrav == 9: a = v[0,0] - v[1,0] b = v[0,1] + v[1,1] c = v[2,2] if ibrav == 10: a = v[2,0] - v[0,0] - v[1,0] b = v[2,1] - v[0,1] + v[1,1] c = v[0,2] - v[1,2] + v[2,2] if ibrav == 11: a = v[0,0] - v[1,0] b = v[1,1] - v[2,1] c = v[0,2] - v[2,2] if ibrav == 12: a = v[0,0] b = sqrt( dot(v[1,:],v[1,:])) cAB = v[1,0]/b c = v[2,2] if ibrav == 13: a = v[0,0] + v[2,0] b = sqrt( dot(v[1,:],v[1,:])) c = v[2,2] - v[0,2] cAB = v[1,0]/b if ibrav == 14: a = v[0,0] b = sqrt( dot(v[1,:],v[1,:])) cAB = v[1,0]/b c = sqrt( dot(v[2,:],v[2,:])) cAC = v[2,0]/c cBC = v[2,1]*sqrt(1.0 - cAB**2)/c + cAC*cAB self.setLattice(ibrav, a, b, c, cBC, cAC, cAB)
def getLatticeParamsFromPWSCF(self, ibrav, fname): qeConf = QEConfig(fname) qeConf.parse() cBC = 0.0 cAC = 0.0 cAB = 0.0 if 'celldm(1)' in qeConf.namelists['system'].params: self._type = 'celldm' # celldm(i), i=1,6 a = float(qeConf.namelist('system').param('celldm(1)')) if ibrav == 0: # lattice is set in the units of celldm(1) # need to parse CELL_PARAMETERS cellParLines = qeConf.card('cell_parameters').getLines() cellParType = qeConf.card('cell_parameters').argument() if cellParType == 'cubic' or cellParType == None: self._type = 'generic cubic' else: if cellParType == 'hexagonal': self._type = 'generic hexagonal' # convert card into list base = [] for line in cellParLines: if '!' not in line: words = line.split() base.append([float(w) for w in words]) return a, None, None, None, None, None, numpy.array(base) if ibrav > 0 and ibrav < 4: return a, a, a, cBC, cAC, cAB, None if ibrav == 4: cAB = cosd(120.0) if ibrav == 4 or ibrav == 6 or ibrav == 7: c_a = float(qeConf.namelist('system').param('celldm(3)')) return a, a, c_a*a, cBC, cAC, cAB, None if ibrav == 5: cAB = float(qeConf.namelist('system').param('celldm(4)')) return a, a, a, cAB, cAB, cAB, None if ibrav > 7 and ibrav < 12: b_a = float(qeConf.namelist('system').param('celldm(2)')) c_a = float(qeConf.namelist('system').param('celldm(3)')) return a, b_a*a, c_a*a, cBC, cAC, cAB, None if ibrav == 12 or ibrav == 13: b_a = float(qeConf.namelist('system').param('celldm(2)')) c_a = float(qeConf.namelist('system').param('celldm(3)')) cAB = float(qeConf.namelist('system').param('celldm(4)')) return a, b_a*a, c_a*a, cBC, cAC, cAB, None if ibrav == 14: b_a = float(qeConf.namelist('system').param('celldm(2)')) c_a = float(qeConf.namelist('system').param('celldm(3)')) cBC = float(qeConf.namelist('system').param('celldm(4)')) cAC = float(qeConf.namelist('system').param('celldm(5)')) cAB = float(qeConf.namelist('system').param('celldm(6)')) return a, b_a*a, c_a*a, cBC, cAC, cAB, None else: if ibrav == 0: print "Should specify celldm(1) if use 'generic' lattice" raise NotImplementedError a = float(qeConf.namelist('system').param('A')) self._type = 'traditional' # A, B, C, cosAB, cosAC, cosBC if ibrav > 0 and ibrav < 4: return a, a, a, cBC, cAC, cAB, None if ibrav == 4: cAB = cosd(120.0) if ibrav == 4 or ibrav == 6 or ibrav == 7: c = float(qeConf.namelist('system').param('C')) return a, a, c, cBC, cAC, cAB, None if ibrav == 5: cAB = float(qeConf.namelist('system').param('cosAB')) return a, a, a, cAB, cAB, cAB, None if ibrav > 7 and ibrav < 12: b = float(qeConf.namelist('system').param('B')) c = float(qeConf.namelist('system').param('C')) return a, b, c, cBC, cAC, cAB, None if ibrav == 12 or ibrav == 13: b = float(qeConf.namelist('system').param('B')) c = float(qeConf.namelist('system').param('C')) cAB = float(qeConf.namelist('system').param('cosAB')) return a, b, c, cBC, cAC, cAB, None if ibrav == 14: b = float(qeConf.namelist('system').param('B')) c = float(qeConf.namelist('system').param('C')) cBC = float(qeConf.namelist('system').param('cosBC')) cAC = float(qeConf.namelist('system').param('cosAC')) cAB = float(qeConf.namelist('system').param('cosAB')) return a, b, c, cBC, cAC, cAB, None
def setLattice(self, ibrav, a = None, b = None, c = None, cBC = None, cAC = None, cAB = None, base = None): """ 'base', numpy array of lattice vectors, and 'a' will only be used if ibrav == 0. Otherwise, ibrav + lattice parameters will be used""" from math import acos # if [ibrav, a,b,c,cBC,cAC,cAB, base] == 8*[None]: # return None if ibrav == None: raise NonImplementedError('ibrav should be specified') self._ibrav = ibrav self._a0 = a if self._ibrav == 0: # print 'Found "generic" cell:' if base == None: raise NonImplementedError('base must be specified') if a == None: a = 1.0 qeBase = numpy.array(base, dtype = float)*a # print qeBase self._a = 1.0 self._primitiveLattice.setLatBase(qeBase) self._standardLattice.setLatBase(qeBase) else: # Make sure all lattice parameters are mutually consistent # according to ibrav. base array is not used: if ibrav < 4 or ibrav == 5: if a is not None: self._a = self._b = self._c = a else: if b is not None: self._a = self._b = self._c = b else: if c is not None: self._a = self._b = self._c = c else: self._b = self._c = self._a if ibrav < 4: self._cBC = self._cAC = self._cAB = 0.0 if ibrav == 4 or ibrav == 6 or ibrav == 7: if a is not None: self._a = self._b = a else: if b is not None: self._a = self._b = b else: self._b = self._a if c is not None: self._c = c if ibrav == 4: self._cAB = cosd(120.0) self._cBC = self._cAC = 0.0 if ibrav == 5: if cBC is not None: self._cBC = self._cAC = self._cAB = cBC else: if cAC is not None: self._cBC = self._cAC = self._cAB = cAC else: if cAB is not None: self._cBC = self._cAC = self._cAB = cAB else: self._cAC = self._cAB = self._cBC if ibrav == 6 or ibrav == 7: self._cBC = self._cAC = self._cAB = 0.0 if ibrav > 7 and ibrav <= 14: if a is not None: self._a = a if b is not None: self._b = b if c is not None: self._c = c if ibrav > 7 and ibrav < 12: self._cBC = self._cAC = self._cAB = 0.0 if ibrav == 12 or ibrav == 13: if cAB is not None: self._cAB = cAB else: if cBC is not None or cAC is not None: raise Exception("Should specify cos(AB) only for" + \ " ibrav = 12 or ibrav = 13" ) self._cBC = self._cAC = 0.0 if ibrav == 14: if cBC is not None: self._cBC = cBC if cAC is not None: self._cAC = cAC if cAB is not None: self._cAB = cAB # if a is not None: self._a = a # if b is not None: self._b = b # if c is not None: self._c = c # if cBC is not None: self._cBC = cBC # if cAC is not None: self._cAC = cAC # if cAB is not None: self._cAB = cAB qeBaseTuple = self._getQEBaseFromParCos(self._ibrav, self._a, self._b, self._c, self._cBC, self._cAC, self._cAB) qeBase = numpy.array(qeBaseTuple[1], dtype = float)*qeBaseTuple[0] # print 'Found "' + qeBaseTuple[2] + '" cell' # print 'Setting the base vectors according to QE conventions:' # print qeBase self._primitiveLattice.setLatBase(qeBase) alpha = degrees(acos(self._cBC)) beta = degrees(acos(self._cAC)) gamma = degrees(acos(self._cAB)) self._standardLattice.setLatPar(self._a,self._b,self._c,alpha,beta,gamma) # print "Standard Lattice:" # print self._standardLattice.base self._base = qeBase
def setLattice(self, ibrav, a = None, b = None, c = None, cBC = None, cAC = None, cAB = None, base = None, updateInput = True): """ 'base', numpy array of lattice vectors, and 'a' will only be used if ibrav == 0. Otherwise, ibrav + lattice parameters will be used""" from math import acos # if [ibrav, a,b,c,cBC,cAC,cAB, base] == 8*[None]: # return None if ibrav == None: raise NonImplementedError('ibrav should be specified') self._ibrav = ibrav if self._ibrav == 0: # print 'Found "generic" cell:' if base == None: raise NonImplementedError('base must be specified') if a == None: raise # a and the base must be provided for ibrav = 0 qeBase = numpy.array(base, dtype = float)#*self._a/a self._a = a # print qeBase #self._a = 1.0 if 'generic' not in self._type: self._type = 'generic cubic' self.__primitiveLattice.setLatBase(qeBase) #self._standardLattice.setLatBase(qeBase) else: # Make sure all lattice parameters are mutually consistent # according to ibrav. base array is not used: if ibrav < 4 or ibrav == 5: if a is not None: self._a = self._b = self._c = a else: if b is not None: self._a = self._b = self._c = b else: if c is not None: self._a = self._b = self._c = c else: self._b = self._c = self._a if ibrav < 4: self._cBC = self._cAC = self._cAB = 0.0 if ibrav == 4 or ibrav == 6 or ibrav == 7: if a is not None: self._a = self._b = a else: if b is not None: self._a = self._b = b else: self._b = self._a if c is not None: self._c = c if ibrav == 4: self._cAB = cosd(120.0) self._cBC = self._cAC = 0.0 if ibrav == 5: if cBC is not None: self._cBC = self._cAC = self._cAB = cBC else: if cAC is not None: self._cBC = self._cAC = self._cAB = cAC else: if cAB is not None: self._cBC = self._cAC = self._cAB = cAB else: self._cAC = self._cAB = self._cBC if ibrav == 6 or ibrav == 7: self._cBC = self._cAC = self._cAB = 0.0 if ibrav > 7 and ibrav <= 14: if a is not None: self._a = a if b is not None: self._b = b if c is not None: self._c = c if ibrav > 7 and ibrav < 12: self._cBC = self._cAC = self._cAB = 0.0 if ibrav == 12 or ibrav == 13: if cAB is not None: self._cAB = cAB else: if cBC is not None or cAC is not None: raise Exception("Should specify cos(AB) only for" + \ " ibrav = 12 or ibrav = 13" ) self._cBC = self._cAC = 0.0 if ibrav == 14: if cBC is not None: self._cBC = cBC if cAC is not None: self._cAC = cAC if cAB is not None: self._cAB = cAB qeBaseTuple = self._getQEBaseFromParCos(self._ibrav, self._a, self._b, self._c, self._cBC, self._cAC, self._cAB) qeBase = numpy.array(qeBaseTuple[1], dtype = float)*qeBaseTuple[0] self.__primitiveLattice.setLatBase(qeBase) alpha = degrees(acos(self._cBC)) beta = degrees(acos(self._cAC)) gamma = degrees(acos(self._cAB)) #self._standardLattice.setLatPar(self._a,self._b,self._c,alpha,beta,gamma) #self._a0 = a self._base = qeBase if self._qeInput != None and updateInput == True: #self.updatePWInput() self._qeInput.update( forceUpdate = True )
def setReducedStructureFromDiffpyStructure(self, structure, ibrav, massList = [], psList = []): """ structure - diffpy.Structure object ibrav - Lattice index psList - list of strings with pseudopotential names diffpyStructure object will be modified with reduced atomic positions """ #self.atomicSpecies = OrderedDict() #self.optConstraints = [] #self.atomicPositionsType = 'crystal' diffpyLattice = structure.lattice a = diffpyLattice.a b = diffpyLattice.b c = diffpyLattice.c cAB = cosd(diffpyLattice.gamma) cBC = cosd(diffpyLattice.alpha) cAC = cosd(diffpyLattice.beta) qeLattice = QELattice(ibrav = ibrav, a = a, b = b, c = c, cBC = cBC, \ cAC = cAC, cAB = cAB) self.lattice = qeLattice # make a deep copy (does not wok now) #reducedStructure = Structure(diffpyStructure) reducedStructure = structure reducedStructure.placeInLattice(Lattice(base=qeLattice.diffpy().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 self._element(a0) == self._element(a1) 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] self.structure = reducedStructure atomNames = [] for a in reducedStructure: if self._element(a) not in atomNames: atomNames.append(self._element(a)) #print atomNames #print len(massList) 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] #print mass, ps # atomDict[a] = # for i, atom in enumerate(reducedStructure): # elem = self._element(atom) # if len(massList) - 1 < i: # mass = 0 # else: # mass = massList[i] # if len(psList) - 1 < i: # ps = '' # else: # ps = psList[i] self.atomicSpecies[elem] = AtomicSpecies(elem, mass, ps) for atom in reducedStructure: self.optConstraints.append([]) # convert to bohr units self.lattice.setLattice(ibrav, self.lattice.a*1.889725989, \ self.lattice.b*1.889725989, self.lattice.c*1.889725989) self.nat = len(reducedStructure) self.ntyp = len(self.atomicSpecies)
def parsePWInput(self, ibrav, qeConf=None): if qeConf == None: qeConf = self.qeConf if qeConf == None: raise NotImplementedError( "writeLatticeToPWSCF: qeConf was not properly initialized") cBC = 0.0 cAC = 0.0 cAB = 0.0 # reset Lattice: #self.setLattice(1. ,1 , 1, cBC ,cAC ,cAB) if 'celldm(1)' in qeConf.namelists['system'].params: self._type = 'celldm' # celldm(i), i=1,6 a = float(qeConf.namelist('system').param('celldm(1)')) if ibrav == 0: # lattice is set in the units of celldm(1) # need to parse CELL_PARAMETERS #if 'cell_parameters' not in qeConf.cards: # return #qeConf.createCard('cell_parameters') cellParLines = qeConf.card('cell_parameters').lines() #print cellParLines cellParType = qeConf.card('cell_parameters').arg() if cellParType == 'cubic' or cellParType == None: self._type = 'generic cubic' else: if cellParType == 'hexagonal': self._type = 'generic hexagonal' # convert card into list base = [] for line in cellParLines: if '!' not in line: words = line.split() base.append([float(w) for w in words]) return a, None, None, None, None, None, numpy.array(base) if ibrav > 0 and ibrav < 4: return a, a, a, cBC, cAC, cAB, None if ibrav == 4: cAB = cosd(120.0) if ibrav == 4 or ibrav == 6 or ibrav == 7: c_a = float(qeConf.namelist('system').param('celldm(3)')) return a, a, c_a * a, cBC, cAC, cAB, None if ibrav == 5: cAB = float(qeConf.namelist('system').param('celldm(4)')) return a, a, a, cAB, cAB, cAB, None if ibrav > 7 and ibrav < 12: b_a = float(qeConf.namelist('system').param('celldm(2)')) c_a = float(qeConf.namelist('system').param('celldm(3)')) return a, b_a * a, c_a * a, cBC, cAC, cAB, None if ibrav == 12 or ibrav == 13: b_a = float(qeConf.namelist('system').param('celldm(2)')) c_a = float(qeConf.namelist('system').param('celldm(3)')) cAB = float(qeConf.namelist('system').param('celldm(4)')) return a, b_a * a, c_a * a, cBC, cAC, cAB, None if ibrav == 14: b_a = float(qeConf.namelist('system').param('celldm(2)')) c_a = float(qeConf.namelist('system').param('celldm(3)')) cBC = float(qeConf.namelist('system').param('celldm(4)')) cAC = float(qeConf.namelist('system').param('celldm(5)')) cAB = float(qeConf.namelist('system').param('celldm(6)')) return a, b_a * a, c_a * a, cBC, cAC, cAB, None else: if ibrav == 0: print "Should specify celldm(1) if use 'generic' lattice" raise NotImplementedError a = float(qeConf.namelist('system').param('A')) self._type = 'traditional' # A, B, C, cosAB, cosAC, cosBC if ibrav > 0 and ibrav < 4: return a, a, a, cBC, cAC, cAB, None if ibrav == 4: cAB = cosd(120.0) if ibrav == 4 or ibrav == 6 or ibrav == 7: c = float(qeConf.namelist('system').param('C')) return a, a, c, cBC, cAC, cAB, None if ibrav == 5: cAB = float(qeConf.namelist('system').param('cosAB')) return a, a, a, cAB, cAB, cAB, None if ibrav > 7 and ibrav < 12: b = float(qeConf.namelist('system').param('B')) c = float(qeConf.namelist('system').param('C')) return a, b, c, cBC, cAC, cAB, None if ibrav == 12 or ibrav == 13: b = float(qeConf.namelist('system').param('B')) c = float(qeConf.namelist('system').param('C')) cAB = float(qeConf.namelist('system').param('cosAB')) return a, b, c, cBC, cAC, cAB, None if ibrav == 14: b = float(qeConf.namelist('system').param('B')) c = float(qeConf.namelist('system').param('C')) cBC = float(qeConf.namelist('system').param('cosBC')) cAC = float(qeConf.namelist('system').param('cosAC')) cAB = float(qeConf.namelist('system').param('cosAB')) return a, b, c, cBC, cAC, cAB, None
def parsePWInput(self, ibrav, qeConf = None): if qeConf == None: qeConf = self.qeConf if qeConf == None: raise NotImplementedError("writeLatticeToPWSCF: qeConf was not properly initialized") cBC = 0.0 cAC = 0.0 cAB = 0.0 # reset Lattice: #self.setLattice(1. ,1 , 1, cBC ,cAC ,cAB) if 'celldm(1)' in qeConf.namelists['system'].params: self._type = 'celldm' # celldm(i), i=1,6 a = float(qeConf.namelist('system').param('celldm(1)')) if ibrav == 0: # lattice is set in the units of celldm(1) # need to parse CELL_PARAMETERS #if 'cell_parameters' not in qeConf.cards: # return #qeConf.createCard('cell_parameters') cellParLines = qeConf.card('cell_parameters').lines() #print cellParLines cellParType = qeConf.card('cell_parameters').arg() if cellParType == 'cubic' or cellParType == None: self._type = 'generic cubic' else: if cellParType == 'hexagonal': self._type = 'generic hexagonal' # convert card into list base = [] for line in cellParLines: if '!' not in line: words = line.split() base.append([float(w) for w in words]) return a, None, None, None, None, None, numpy.array(base) if ibrav > 0 and ibrav < 4: return a, a, a, cBC, cAC, cAB, None if ibrav == 4: cAB = cosd(120.0) if ibrav == 4 or ibrav == 6 or ibrav == 7: c_a = float(qeConf.namelist('system').param('celldm(3)')) return a, a, c_a*a, cBC, cAC, cAB, None if ibrav == 5: cAB = float(qeConf.namelist('system').param('celldm(4)')) return a, a, a, cAB, cAB, cAB, None if ibrav > 7 and ibrav < 12: b_a = float(qeConf.namelist('system').param('celldm(2)')) c_a = float(qeConf.namelist('system').param('celldm(3)')) return a, b_a*a, c_a*a, cBC, cAC, cAB, None if ibrav == 12 or ibrav == 13: b_a = float(qeConf.namelist('system').param('celldm(2)')) c_a = float(qeConf.namelist('system').param('celldm(3)')) cAB = float(qeConf.namelist('system').param('celldm(4)')) return a, b_a*a, c_a*a, cBC, cAC, cAB, None if ibrav == 14: b_a = float(qeConf.namelist('system').param('celldm(2)')) c_a = float(qeConf.namelist('system').param('celldm(3)')) cBC = float(qeConf.namelist('system').param('celldm(4)')) cAC = float(qeConf.namelist('system').param('celldm(5)')) cAB = float(qeConf.namelist('system').param('celldm(6)')) return a, b_a*a, c_a*a, cBC, cAC, cAB, None else: if ibrav == 0: print "Should specify celldm(1) if use 'generic' lattice" raise NotImplementedError a = float(qeConf.namelist('system').param('A')) self._type = 'traditional' # A, B, C, cosAB, cosAC, cosBC if ibrav > 0 and ibrav < 4: return a, a, a, cBC, cAC, cAB, None if ibrav == 4: cAB = cosd(120.0) if ibrav == 4 or ibrav == 6 or ibrav == 7: c = float(qeConf.namelist('system').param('C')) return a, a, c, cBC, cAC, cAB, None if ibrav == 5: cAB = float(qeConf.namelist('system').param('cosAB')) return a, a, a, cAB, cAB, cAB, None if ibrav > 7 and ibrav < 12: b = float(qeConf.namelist('system').param('B')) c = float(qeConf.namelist('system').param('C')) return a, b, c, cBC, cAC, cAB, None if ibrav == 12 or ibrav == 13: b = float(qeConf.namelist('system').param('B')) c = float(qeConf.namelist('system').param('C')) cAB = float(qeConf.namelist('system').param('cosAB')) return a, b, c, cBC, cAC, cAB, None if ibrav == 14: b = float(qeConf.namelist('system').param('B')) c = float(qeConf.namelist('system').param('C')) cBC = float(qeConf.namelist('system').param('cosBC')) cAC = float(qeConf.namelist('system').param('cosAC')) cAB = float(qeConf.namelist('system').param('cosAB')) return a, b, c, cBC, cAC, cAB, None