def freq(strchg, numAtomsUC, gulpName, tempName): """ Executes a gulp program with the string changes neccesary and returns the frequencies. ntpy.gulp.freq(strchg, numAtomsUC, gulpName, tempName) Parameters ---------- strchg : dict of type str A dictionary holding key:value pairs. Each key is original string to be replaced and each value is the new string to be subsituted. numAtomsUC : int The number of atoms in the unit cell. gulpName : str A string containing the original file name. If the file is not included in the pathway then it can be the absolute or relative pathway to the file. tempName : str A string containing the new file name. If the file is not included in the pathway then it can be the absolute or relative pathway to the file. """ # String change the template file st.sed(strchg, gulpName, tempName) # Execute the new gulp file os.system('gulp <'+ tempName+ ' > output.gulp') # os.system('gulp '+ tempName+ ' output.gulp') # Extract the frequencies freq = np.zeros( (3 * numAtomsUC), dtype=float) freq = np.loadtxt(tempName+ '.freq', comments='--') freq[:] = freq[:] * 2.0 * np.pi * ct.value('c') * ct.value('tocenti') * lj.value('tau') # Remove the .freq file os.system('rm '+ tempName+ '.freq') return freq
def vel(strchg, numAtomsUC, gulpName, tempName, kpt, latConst, deltaKpt=1e-3, gulpExe='gulp'): """ Executes a gulp program with the string changes neccesary and returns the velocities. ntpy.gulp.vel(strchg, numAtomsUC, gulpName, tempName, deltaKpt=1e-3, gulpExe='gulp') Parameters ---------- strchg : dict of type str A dictionary holding key:value pairs. Each key is original string to be replaced and each value is the new string to be subsituted. numAtomsUC : int The number of atoms in the unit cell. gulpName : str A string containing the original file name. If the file is not included in the pathway then it can be the absolute or relative pathway to the file. tempName : str A string containing the new file name. If the file is not included in the pathway then it can be the absolute or relative pathway to the file. kpt : array of type float A numpy array of size 3 that has the three dimension k-point to be used. latConst : float A float of the lattice constant in angstroms. deltaKpt : float, optional A float that determines what difference to use for the difference theorem. Defaults to 10e-5. gulpExe : str, optional A string of the gulp executable. Defaults to "gulp". Returns ---------- vel : numpy array of type float Returns the velocity for the kpt in a array of shape (3 * numAtomsUC, 3) """ def _kptstrchg(strchg, kpt): strchg['KPT'] = '{:.10f} {:.10f} {:.10f}'.format( kpt[0], kpt[1], kpt[2]) return strchg vel = np.zeros((3 * numAtomsUC, 3), dtype=float) # Convert to m/s velConv = ((1.0 / ct.value('centi')) * ct.value('c')) / (1.0 / (latConst * ct.value('ang'))) # For all three directions for idim in range(3): if kpt[idim] == 0.5: # kpt at right boundary freqVal = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) # Change kpt kpt[idim] = kpt[idim] - deltaKpt strchg = _kptstrchg(strchg, kpt) freqValMdk = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) vel[:, idim] = ((freqVal - freqValMdk) / deltaKpt) * velConv # Reset kpt kpt[idim] = kpt[idim] + deltaKpt strchg = _kptstrchg(strchg, kpt) elif kpt[idim] == -0.5: # kpt at left boundary freqVal = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) # Change kpt kpt[idim] = kpt[idim] + deltaKpt strchg = _kptstrchg(strchg, kpt) freqValPdk = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) vel[:, idim] = ((freqValPdk - freqVal) / deltaKpt) * velConv # Reset kpt kpt[idim] = kpt[idim] - deltaKpt strchg = _kptstrchg(strchg, kpt) elif kpt[idim] == 0.0: # kpt at gamma point freqVal = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) # Change kpt kpt[idim] = kpt[idim] + deltaKpt strchg = _kptstrchg(strchg, kpt) freqValPdk = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) vel[:, idim] = ((freqValPdk - freqVal) / deltaKpt) * velConv # Reset kpt kpt[idim] = kpt[idim] - deltaKpt strchg = _kptstrchg(strchg, kpt) else: freqVal = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) # Change kpt kpt[idim] = kpt[idim] + deltaKpt strchg = _kptstrchg(strchg, kpt) freqValPdk = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) kpt[idim] = kpt[idim] - (2.0 * deltaKpt) strchg = _kptstrchg(strchg, kpt) freqValMdk = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) vel[:, idim] = ((freqValPdk - freqValMdk) / (2.0 * deltaKpt)) * velConv # Reset kpt kpt[idim] = kpt[idim] + deltaKpt strchg = _kptstrchg(strchg, kpt) return vel
def vel(strchg, numAtomsUC, gulpName, tempName, kpt, latConst, deltaKpt=1e-3, gulpExe='gulp'): """ Executes a gulp program with the string changes neccesary and returns the velocities. ntpy.gulp.vel(strchg, numAtomsUC, gulpName, tempName, deltaKpt=1e-3, gulpExe='gulp') Parameters ---------- strchg : dict of type str A dictionary holding key:value pairs. Each key is original string to be replaced and each value is the new string to be subsituted. numAtomsUC : int The number of atoms in the unit cell. gulpName : str A string containing the original file name. If the file is not included in the pathway then it can be the absolute or relative pathway to the file. tempName : str A string containing the new file name. If the file is not included in the pathway then it can be the absolute or relative pathway to the file. kpt : array of type float A numpy array of size 3 that has the three dimension k-point to be used. latConst : float A float of the lattice constant in angstroms. deltaKpt : float, optional A float that determines what difference to use for the difference theorem. Defaults to 10e-5. gulpExe : str, optional A string of the gulp executable. Defaults to "gulp". Returns ---------- vel : numpy array of type float Returns the velocity for the kpt in a array of shape (3 * numAtomsUC, 3) """ def _kptstrchg(strchg, kpt): strchg['KPT'] = '{:.10f} {:.10f} {:.10f}'.format(kpt[0], kpt[1], kpt[2]) return strchg vel = np.zeros( (3 * numAtomsUC, 3), dtype=float) # Convert to m/s velConv = ((1.0 / ct.value('centi')) * ct.value('c')) / (1.0 / (latConst * ct.value('ang'))) # For all three directions for idim in range(3): if kpt[idim] == 0.5: # kpt at right boundary freqVal = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) # Change kpt kpt[idim] = kpt[idim] - deltaKpt strchg = _kptstrchg(strchg, kpt) freqValMdk = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) vel[:, idim] = ((freqVal - freqValMdk) / deltaKpt) * velConv # Reset kpt kpt[idim] = kpt[idim] + deltaKpt strchg = _kptstrchg(strchg, kpt) elif kpt[idim] == -0.5: # kpt at left boundary freqVal = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) # Change kpt kpt[idim] = kpt[idim] + deltaKpt strchg = _kptstrchg(strchg, kpt) freqValPdk = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) vel[:, idim] = ((freqValPdk - freqVal) / deltaKpt) * velConv # Reset kpt kpt[idim] = kpt[idim] - deltaKpt strchg = _kptstrchg(strchg, kpt) elif kpt[idim] == 0.0: # kpt at gamma point freqVal = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) # Change kpt kpt[idim] = kpt[idim] + deltaKpt strchg = _kptstrchg(strchg, kpt) freqValPdk = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) vel[:, idim] = ((freqValPdk - freqVal) / deltaKpt) * velConv # Reset kpt kpt[idim] = kpt[idim] - deltaKpt strchg = _kptstrchg(strchg, kpt) else: freqVal = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) # Change kpt kpt[idim] = kpt[idim] + deltaKpt strchg = _kptstrchg(strchg, kpt) freqValPdk = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) kpt[idim] = kpt[idim] - (2.0 * deltaKpt) strchg = _kptstrchg(strchg, kpt) freqValMdk = freq(strchg, numAtomsUC, gulpName, tempName, gulpExe=gulpExe) vel[:, idim] = ((freqValPdk - freqValMdk) / (2.0 * deltaKpt)) * velConv # Reset kpt kpt[idim] = kpt[idim] + deltaKpt strchg = _kptstrchg(strchg, kpt) return vel