def __init__(self, filePath): self.text = open(filePath, 'r').readlines() self.parser = b_PyParse.MainSCFParser(self.text) self.parser.parse()
def __init__(self, **arguments): ############################ ######### PARSING ########## ############################ ###Rest of the Files### #parse all the things! #### *.struct file parser parser_struct_handle = open(arguments['file_struct'], 'r').readlines() parser_struct_handle = b_PyParse.MainStructParser(parser_struct_handle) parser_struct_handle.parse() #### *.scf file parser parser_scf_handle = open(arguments['file_scf'], 'r').readlines() parser_scf_handle = b_PyParse.MainSCFParser(parser_scf_handle) parser_scf_handle.parse() #### *.outputd parser parser_outputd_handle = open(arguments['file_outputd'], 'r').readlines() parser_outputd_handle = b_PyParse.MainOutputDParser( parser_outputd_handle) parser_outputd_handle.parse() #### *.outputst parser parser_outputst_handle = open(arguments['file_outputst'], 'r').readlines() parser_outputst_handle = b_PyParse.MainOutputstParser( parser_outputst_handle) parser_outputst_handle.parse() ##################################### ############ END Parsing ############ ##################################### ############################# ###### Getting Values ####### ############################# self._calculationValues = orderedDict() #### *.struct handle # - determine name of atoms # - determine MULT for each atom self._calculationValues['Atom Listing'] = parser_struct_handle[ 'Atom Listing'] #### *.scf handle # - Cell Volume self._calculationValues['Cell Volume in bohr^3'] = parser_scf_handle[ 'Cell Volume'] self._calculationValues['Cell Volume in m^3'] = bohrToMeters( self._calculationValues['Cell Volume in bohr^3'], 3) #### *.outputd handle # - BR2_DIR matrix (v_x, v_y, v_z) # - number of atoms in cell # - Lattice Constants (x,y,z) laticematrix = parser_outputd_handle['BR2_DIR Matrix'] latticematrixa1 = laticematrix[0] self._calculationValues['Lattice Matrix a1 in bohr'] = latticematrixa1 latticematrixa2 = laticematrix[1] self._calculationValues['Lattice Matrix a2 in bohr'] = latticematrixa2 latticematrixa3 = laticematrix[2] self._calculationValues['Lattice Matrix a3 in bohr'] = latticematrixa3 self._calculationValues[ 'Lattice Matrix in bohr'] = parser_outputd_handle['BR2_DIR Matrix'] self._calculationValues['Lattice Matrix in m'] = [[ bohrToMeters(i) for i in j ] for j in self._calculationValues['Lattice Matrix in bohr']] self._calculationValues[ 'Number of Atoms in Unit Cell'] = parser_outputd_handle[ 'Number of Atoms in Unit Cell'] self._calculationValues[ 'Lattice Constants in bohr'] = parser_outputd_handle[ 'Lattice Constants'] self._calculationValues['Lattice Constants in m'] = [ bohrToMeters(i) for i in self._calculationValues['Lattice Constants in bohr'] ] #### *.outputst handle # for each element: # - Core Value # - Spin Value 1 # - Spin Value 2 self._calculationValues['Element Listing'] = parser_outputst_handle[ 'Element List'] #### #### PATHPHASE #### #*.pathphases parsers #get text strings from each file phaseFilesList = [ arguments['file_pathphase_x'], arguments['file_pathphase_y'], arguments['file_pathphase_z'], ] #read from files phaseTextStringsList = [ open(i, 'r').readlines() for i in phaseFilesList ] #parse the values phaseValues = [ b_PyParse.MainPathphaseParser(i) for i in phaseTextStringsList ] for i in phaseValues: i.parse() #send to pathphasecalculation for correction self.phaseValues = phaseValues phaseObjects = [ PathphaseCalculation(values=i['values']) for i in phaseValues ] self.value_phaseConsistentDomainValues = [ i.getConsistentDomainValues() for i in phaseObjects ] self.value_phaseConsistentDomainValues2 = [ i.getConsistentDomainValues2() for i in phaseObjects ] self.value_phaseCorrectedValues = [ i.getCorrectedValues() for i in phaseObjects ] self.value_phaseCorrectedValues2 = [ i.getCorrectedValues2() for i in phaseObjects ] #receive mean values self.value_phaseMeanValues = value_phaseMeanValues = [ i.getMeanValue() for i in phaseObjects ] #constants #electron charge / unit volume self.ELEC_BY_VOL_CONST = ELECTRON_CHARGE / bohrToMeters( self._calculationValues['Cell Volume in bohr^3'], dimension=3.) #perform necessary calculations self.determineElectronPolarization() self.determineIonPolarization() self.calculateNetPolarizationEnergy()
def __init__(self, **args): # spin polarization: yes/no spCalc = args['sp'] ############################ ######### PARSING ########## ############################ ###Rest of the Files### #parse all the things! #### *.struct file parser parser_struct_handle = open(args['file_struct'], 'r').readlines() parser_struct_handle = b_PyParse.MainStructParser(parser_struct_handle) parser_struct_handle.parse() #### *.scf file parser parser_scf_handle = open(args['file_scf'], 'r').readlines() parser_scf_handle = b_PyParse.MainSCFParser(parser_scf_handle) parser_scf_handle.parse() #### *.outputd parser parser_outputd_handle = open(args['file_outputd'], 'r').readlines() parser_outputd_handle = b_PyParse.MainOutputDParser( parser_outputd_handle) parser_outputd_handle.parse() #### *.outputst parser parser_outputst_handle = open(args['file_outputst'], 'r').readlines() parser_outputst_handle = b_PyParse.MainOutputstParser( parser_outputst_handle) parser_outputst_handle.parse() ##################################### ############ END Parsing ############ ##################################### ############################# ###### Getting Values ####### ############################# self._calculationValues = orderedDict() #### *.struct handle # - determine name of atoms # - determine MULT for each atom self._calculationValues['Atom Listing'] = \ parser_struct_handle['Atom Listing'] #### *.scf handle # - Cell Volume self._calculationValues['Cell Volume in bohr^3'] = \ parser_scf_handle['Cell Volume'] self._calculationValues['Cell Volume in m^3'] = \ bohrToMeters(self._calculationValues['Cell Volume in bohr^3'],3) #### *.outputd handle # - BR2_DIR matrix (v_x, v_y, v_z) # - number of atoms in cell # - Lattice Constants (x,y,z) laticematrix = parser_outputd_handle['BR2_DIR Matrix'] latticematrixa1 = laticematrix[0] self._calculationValues['Lattice Matrix a1 in bohr'] = \ latticematrixa1 latticematrixa2 = laticematrix[1] self._calculationValues['Lattice Matrix a2 in bohr'] = \ latticematrixa2 latticematrixa3 = laticematrix[2] self._calculationValues['Lattice Matrix a3 in bohr'] = \ latticematrixa3 self._calculationValues['Lattice Matrix in bohr'] = \ parser_outputd_handle['BR2_DIR Matrix'] self._calculationValues['Lattice Matrix in m'] = \ [[ bohrToMeters(i) for i in j ] for j in \ self._calculationValues['Lattice Matrix in bohr']] self._calculationValues['Number of Atoms in Unit Cell'] = \ parser_outputd_handle['Number of Atoms in Unit Cell'] self._calculationValues['Lattice Constants in bohr'] = \ parser_outputd_handle['Lattice Constants'] self._calculationValues['Lattice Constants in m'] = \ [ bohrToMeters(i) for i in \ self._calculationValues['Lattice Constants in bohr']] #### *.outputst handle # for each element: # - Core Value # - Spin Value 1 # - Spin Value 2 self._calculationValues['Element Listing'] = \ parser_outputst_handle['Element List'] #### ######################## # get electronic phase # ######################## # get raw list [k-points, phase] phaseDirSpinPathRaw = args['phases'] # wrap phases in the range [-pi ... +pi] phaseDirSpinPathWrp11 = self.wrpPhase(phaseDirSpinPathRaw, \ self.wrp11) # print nice print "\n","Initial Berry phases and their", \ "wrapped values in the range [-pi ... +pi]" print "=" * 87 print " "*30, "| init k-point", "| phase raw (rad)", \ "| phase wrap. (rad)" icoord = -1 for coord in phaseDirSpinPathRaw: icoord += 1 print "-" * 87 print "direction(%u)" % int(icoord + 1) ispin = -1 for spin in coord: ispin += 1 print " " * 12, "spin(%u)" % int(ispin + 1) ipath = -1 for path in spin: ipath += 1 # perform wraping using the method privided in input kpt = phaseDirSpinPathRaw[icoord][ispin][ipath][0] ph = phaseDirSpinPathRaw[icoord][ispin][ipath][1] phwrp = phaseDirSpinPathWrp11[icoord][ispin][ipath][1] print " "*20, "path(%4d) %4d % e % e" \ % (ipath+1, kpt, ph, phwrp) print "=" * 87 print "\n", "CALCULATION OF ELECTRONIC POLARIZATION" print "=" * 87 print "Value", " "*25, "| spin ", "| ", "dir(1) ", \ "| ", "dir(2) ", "| ", "dir(3)" print "-" * 87 # find path-average phase phaseDirSpinWrp11 = self.pathAvrgPhase(phaseDirSpinPathWrp11) # wrap the average phase again as it can go out of bounds [-pi..+pi] phaseDirSpinWrp11 = self.wrp11(phaseDirSpinWrp11) nspins = numpy.shape(phaseDirSpinWrp11)[1] for spinIndex in range(0, nspins): print "Berry phase (rad) [-pi ... +pi] sp(%1i)" \ % (spinIndex+1), \ " [% e, % e, % e]" % tuple(phaseDirSpinWrp11[:,spinIndex]) if not spCalc and not args[ 'so']: # in case of non-SP or non-SO calculation... phaseDirSpinWrp11 = 2 * phaseDirSpinWrp11 # account for the spin degeneracy nspins = numpy.shape(phaseDirSpinWrp11)[1] if nspins != 1: # double check print "Inconsistency detected in the number of spins" print "Is it spin-polarized calculation? spCalc =", spCalc print "Number of spins in the electronic phase array", \ nspins print "Expected 1 spin" print "Decision is taken to EXIT" sys.exit(2) print "Berry phase (rad) up+dn "+ \ "[% e, % e, % e]" % tuple(phaseDirSpinWrp11) # wrap phases again [-pi ... +pi] phaseDirSpinWrp11 = self.wrp11(phaseDirSpinWrp11) print "Berry phase (rad) [-pi ... +pi] " +\ " up+dn [% e, % e, % e]" \ % tuple(phaseDirSpinWrp11) #electron charge / cell volume self.ELEC_BY_VOL_CONST = ELECTRON_CHARGE / \ bohrToMeters(self._calculationValues['Cell Volume in bohr^3'], \ dimension = 3.) # electronic polarization (C/m2) elP = self.elPolarization(phaseDirSpinWrp11,self._calculationValues, \ self.ELEC_BY_VOL_CONST) # ionic polarization (C/m2) ionP = self.determineIonPolarization(self.wrp11, args) # Total polarization (C/m2) will be returned # when calling mainCalculation() self._totalPolarizationVal = self.totalPolarization(elP, ionP)