Ejemplo n.º 1
0
 def getStress(self):
     stress = [None] * 9
     for i in range(0, self.pwFile.lineCount):
         if 'total   stress ' in self.pwFile.fileData[i]:
             i = i + 1
             fileRow = oStrings.removeDouble(self.pwFile.fileData[i], " ")
             fileRow = oStrings.trimEnds(fileRow)
             stressArr = fileRow.split(" ")
             stress[0] = float(stressArr[0])
             stress[1] = float(stressArr[1])
             stress[2] = float(stressArr[2])
             i = i + 1
             fileRow = oStrings.removeDouble(self.pwFile.fileData[i], " ")
             fileRow = oStrings.trimEnds(fileRow)
             stressArr = fileRow.split(" ")
             stress[3] = float(stressArr[0])
             stress[4] = float(stressArr[1])
             stress[5] = float(stressArr[2])
             i = i + 1
             fileRow = oStrings.removeDouble(self.pwFile.fileData[i], " ")
             fileRow = oStrings.trimEnds(fileRow)
             stressArr = fileRow.split(" ")
             stress[6] = float(stressArr[0])
             stress[7] = float(stressArr[1])
             stress[8] = float(stressArr[2])
     return stress
Ejemplo n.º 2
0
 def getCell_Relaxed(self):
     cell = [[0 for x in range(3)] for y in range(3)]
     inRelaxed = False
     for i in range(0, self.pwFile.lineCount):
         if 'A final scf calculation' in self.pwFile.fileData[i]:
             inRelaxed = True
         if (inRelaxed):
             if 'crystal axes:' in self.pwFile.fileData[i]:
                 i = i + 1
                 dataRow = oStrings.removeDouble(self.pwFile.fileData[i],
                                                 " ")
                 dataRow = oStrings.trimEnds(dataRow)
                 dataArr = dataRow.split(" ")
                 cell[0][0] = float(dataArr[3])
                 cell[0][1] = float(dataArr[4])
                 cell[0][2] = float(dataArr[5])
                 i = i + 1
                 dataRow = oStrings.removeDouble(self.pwFile.fileData[i],
                                                 " ")
                 dataRow = oStrings.trimEnds(dataRow)
                 dataArr = dataRow.split(" ")
                 cell[1][0] = float(dataArr[3])
                 cell[1][1] = float(dataArr[4])
                 cell[1][2] = float(dataArr[5])
                 i = i + 1
                 dataRow = oStrings.removeDouble(self.pwFile.fileData[i],
                                                 " ")
                 dataRow = oStrings.trimEnds(dataRow)
                 dataArr = dataRow.split(" ")
                 cell[2][0] = float(dataArr[3])
                 cell[2][1] = float(dataArr[4])
                 cell[2][2] = float(dataArr[5])
     return cell
Ejemplo n.º 3
0
 def normaliseParameters(self):
     # Set the cell_parameter matrix such that (1,1) = 1.0 and adjust aLat accordingly
     aLat = 0.0e0
     cellParameters = [[0 for x in range(3)] for y in range(3)]
     for i in range(0, self.pwFile.lineCount):
         if 'celldm(1)' in self.pwFile.fileData[i]:
             aLat = self.getInput(self.pwFile.fileData[i])
         if 'CELL_PARAMETERS' in self.pwFile.fileData[i]:
             for j in range(0, 3):
                 i = i + 1
                 fileRow = oStrings.removeDouble(self.pwFile.fileData[i],
                                                 " ")
                 fileRow = fileRow.split(" ")
                 for k in range(0, 3):
                     cellParameters[j][k] = float(fileRow[k])
     topVal = cellParameters[0][0]
     # Change aLat
     aLat = aLat * topVal
     # Change cell
     for j in range(0, 3):
         for k in range(0, 3):
             if (j == 0 and k == 0):
                 cellParameters[j][k] = 1.0
             else:
                 cellParameters[j][k] = cellParameters[j][k] / topVal
     self.changeAlat(aLat)
     self.changeCellParameters(cellParameters)
Ejemplo n.º 4
0
 def increaseSize(self, copyX, copyY=None, copyZ=None):
     label = []
     x = []
     y = []
     z = []
     fileTemp = []
     fileBottom = []
     if (copyY == None):
         copyY = copyX
     if (copyZ == None):
         copyZ = copyX
     nat = self.getNAT()
     aLat = self.getAlat()
     nat_New = 0
     aLat_New = aLat * copyX
     j = 0
     rowCounter = 0
     for i in range(0, self.pwFile.lineCount):
         if (j == 0):
             fileTemp.append(self.pwFile.fileData[i])
             rowCounter = rowCounter + 1
         if (j > nat):
             fileTemp.append(self.pwFile.fileData[i])
             rowCounter = rowCounter + 1
         if (j > 0 and j <= nat):
             fileRow = oStrings.removeDouble(self.pwFile.fileData[i], " ")
             fileRowArr = fileRow.split(" ")
             label.append(fileRowArr[0])
             x.append(float(fileRowArr[1]))
             y.append(float(fileRowArr[2]))
             z.append(float(fileRowArr[3]))
             j = j + 1
         if (j == (nat + 1)):
             j = j + 1
             # Make structure
             for xx in range(0, copyX):
                 for yy in range(0, copyY):
                     for zz in range(0, copyZ):
                         for n in range(0, nat):
                             nat_New = nat_New + 1
                             label_ext = str(label[n])
                             x_ext = str((xx + x[n]) / copyX)
                             y_ext = str((yy + y[n]) / copyY)
                             z_ext = str((zz + z[n]) / copyZ)
                             row = label_ext + " " + x_ext + " " + y_ext + " " + z_ext
                             rowCounter = rowCounter + 1
                             fileTemp.append(row)
         if (self.checkString(self.pwFile.fileData[i], "ATOMIC_POSITIONS")):
             j = j + 1
     self.pwFile.fileData = fileTemp
     self.pwFile.lineCount = rowCounter
     self.changeNat(nat_New)
     self.changeAlat(float(aLat_New))
Ejemplo n.º 5
0
 def getAtomPP(self, atomID):
     nType = self.getNType()
     atomID = atomID % nType
     for i in range(0, self.pwFile.lineCount):
         if 'ATOMIC_SPECIES' in self.pwFile.fileData[i].upper():
             for j in range(0, nType):
                 i = i + 1
                 fileRow = oStrings.removeDouble(self.pwFile.fileData[i],
                                                 " ")
                 fileRowArr = fileRow.split(" ")
                 if (j == atomID):
                     return fileRowArr[2]
             break
Ejemplo n.º 6
0
 def checkKeyword(lineIn, keyword, verbose=False):
     result = None
     if (lineIn != ""):
         lineInArr = lineIn.split("#")
         lineIn = lineInArr[0]
         if (lineIn != ""):
             lineInUC = lineIn.upper()
             keywordUC = keyword.upper()
             keywordLen = len(keywordUC)
             if (lineInUC[0:keywordLen] == keywordUC):
                 result = oStrings.removeDouble(lineIn, " ")
                 if (verbose):
                     print(result)
     return result
Ejemplo n.º 7
0
 def readAtomSpecies(self):
     self.atomSpecies_symbol = []
     self.atomSpecies_mass = []
     self.atomSpecies_pp = []
     for i in range(0, self.pwFile.lineCount):
         if 'ATOMIC_SPECIES' in self.pwFile.fileData[i].upper():
             for j in range(0, self.ntype):
                 i = i + 1
                 fileRow = oStrings.removeDouble(self.pwFile.fileData[i],
                                                 " ")
                 fileRowArr = fileRow.split(" ")
                 self.atomSpecies_symbol.append(fileRowArr[0])
                 self.atomSpecies_mass.append(fileRowArr[1])
                 self.atomSpecies_pp.append(fileRowArr[2])
Ejemplo n.º 8
0
 def extractData(self):
     self.aLat = 0.0e0
     self.cellParameters = [[0 for x in range(3)] for y in range(3)]
     self.nat = 0
     self.ntype = 0
     self.atomSpecies_symbol = []
     self.atomSpecies_mass = []
     self.atomSpecies_pp = []
     for i in range(0, self.pwFile.lineCount):
         if 'CELLDM(1)' in self.pwFile.fileData[i].upper():
             self.aLat = self.getInput(self.pwFile.fileData[i])
         if 'CELL_PARAMETERS' in self.pwFile.fileData[i].upper():
             for j in range(0, 3):
                 i = i + 1
                 fileRow = oStrings.removeDouble(self.pwFile.fileData[i],
                                                 " ")
                 fileRow = fileRow.split(" ")
                 for k in range(0, 3):
                     self.cellParameters[j][k] = float(fileRow[k])
         if 'NTYP' in self.pwFile.fileData[i].upper():
             fileRow = self.pwFile.fileData[i].replace(",", "")
             fileRowArr = fileRow.split("=")
             self.ntype = int(fileRowArr[1])
         if 'NAT' in self.pwFile.fileData[i].upper():
             fileRow = self.pwFile.fileData[i].replace(",", "")
             fileRowArr = fileRow.split("=")
             self.nat = int(fileRowArr[1])
         if 'ATOMIC_SPECIES' in self.pwFile.fileData[i].upper():
             for j in range(0, self.ntype):
                 i = i + 1
                 fileRow = oStrings.removeDouble(self.pwFile.fileData[i],
                                                 " ")
                 fileRowArr = fileRow.split(" ")
                 self.atomSpecies_symbol.append(fileRowArr[0])
                 self.atomSpecies_mass.append(fileRowArr[1])
                 self.atomSpecies_pp.append(fileRowArr[2])
Ejemplo n.º 9
0
 def getAlat_RelaxedNormalised(self):
     inRelaxed = False
     for i in range(0, self.pwFile.lineCount):
         if 'A final scf calculation' in self.pwFile.fileData[i]:
             inRelaxed = True
         if (inRelaxed):
             if 'lattice parameter (alat)  =' in self.pwFile.fileData[i]:
                 tString = self.pwFile.fileData[i].upper()
                 tString = tString.split("=")
                 tString = tString[1]
                 tString = tString.split("A.U.")
                 aLat = float(tString[0])
             if 'crystal axes:' in self.pwFile.fileData[i]:
                 i = i + 1
                 dataRow = oStrings.removeDouble(self.pwFile.fileData[i],
                                                 " ")
                 dataRow = oStrings.trimEnds(dataRow)
                 dataArr = dataRow.split(" ")
                 aLat = aLat * float(dataArr[3])
     return aLat
Ejemplo n.º 10
0
    def changeKpoints(self, kpoints):
        # Check input
        kpoints = str(kpoints)
        kpoints = oStrings.removeDouble(kpoints, " ")
        kpoints = oStrings.trimEnds(kpoints)
        kpoints = kpoints
        kpointsArr = kpoints.split(" ")
        print(len(kpointsArr))
        if (len(kpointsArr) == 6):
            kpoints_row = str(kpointsArr[0]) + " " + str(
                kpointsArr[1]) + " " + str(kpointsArr[2]) + " " + "   1 1 1"
        if (len(kpointsArr) == 3):
            kpoints_row = str(kpointsArr[0]) + " " + str(
                kpointsArr[1]) + " " + str(kpointsArr[2]) + " " + "   1 1 1"
        if (len(kpointsArr) == 1):
            kpoints_row = str(kpointsArr[0]) + " " + str(
                kpointsArr[0]) + " " + str(kpointsArr[0]) + "   1 1 1"

        for i in range(0, self.pwFile.lineCount):
            if 'K_POINTS' in self.pwFile.fileData[i].upper():
                self.pwFile.fileData[i] = 'K_POINTS automatic'
                self.pwFile.fileData[i + 1] = kpoints_row
Ejemplo n.º 11
0
 def heat(self, maxVariation):
     # Set up random number
     rd = RandDist()
     rd.gheat(-1.0, 1.0, 1.0, 0.0, 1.0, 4.0)
     # Get atom numbers
     nAtoms = self.getNAT()
     # Get lattice parameter
     aLat = self.getAlat()
     # Crystal variation
     variation = maxVariation * (1.0 / aLat)
     # Loop through rows
     for i in range(0, self.pwFile.lineCount):
         testStr = self.pwFile.fileData[i]
         testStrU = testStr.upper()
         # Update data file
         if ('ATOMIC_POSITIONS' in testStrU):
             for k in range(0, nAtoms):
                 i = i + 1
                 if (self.pwFile.fileData[i] == ""):
                     k = k - 1
                 else:
                     fileRow = oStrings.removeDouble(
                         self.pwFile.fileData[i], " ")
                     fileRow = fileRow.split(" ")
                     newRow = fileRow[0] + " "
                     x = float(fileRow[1])
                     x = x + variation * rd.rng()
                     x = x % 1
                     y = float(fileRow[2])
                     y = y + variation * rd.rng()
                     y = y % 1
                     z = float(fileRow[3])
                     z = z + variation * rd.rng()
                     z = z % 1
                     newRow = newRow + str(x) + " " + str(y) + " " + str(z)
                     self.pwFile.fileData[i] = newRow