def p4vaspStruct2UnitCell(struct): """Utility to build a UnitCell instance from a P4VASP structure. The atom types are not known from the POSCAR only (need POTCAR), but they are known if the Structure isntance is built from parsing the vasp.xml file properly, eg: from p4vasp.SystemPM import * from p4vasp.Structure import Structure run=XMLSystemPM('vasprun.xml') struct=run.FINAL_STRUCTURE """ try: from AbInitio.vasp.parsing.Structure import Structure except ImportError: print "P4Vasp could not be imported in Python." uc = UnitCell() cellvecs = [v.data for v in struct.basis] uc.setCellVectors(cellvecs) atomindex = 0 for v in struct.positions: vaspatomstring = struct.getRecordForAtom(atomindex)['element'] atomstring = vaspatomstring.split('_')[0] atom = Atom(symbol=atomstring.strip()) site = Site(position=v.data, atom=atom) uc.addSite(site, siteId='') atomindex += 1 return uc
def test2(): import crystal.UnitCell as UC from crystal.Atom import Atom path = ExcitationSlicer.__file__.strip('__init__.pyc') cellvectors = [[3.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 3.0]] #uc = UC.create_unitcell(cellvectors, [Atom(Z=23), Atom(Z=23)], [(0,0,0), (0.5, 0.5, 0.5)]) uc = UC.UnitCell() uc.setCellVectors(cellvectors) uc.addAtom(Atom(Z=23), (0, 0, 0), '') uc.addAtom(Atom(Z=23), (0.5, 0.5, 0.5), '') #Now we want to plot the isosurface with intensity mapped on it: myplotter2 = VTKIsoSurfaceIntensityPlotter() calc2 = phonIsoSurfaceCalcor(unitcell=uc, tau=[1.0, 0.0, 0.0], plotter=myplotter2) calc2.setDataFile(path + 'data/phon_out.pkl') calc2.loadPhononData() calc2.plotIsoSurfaceIntensity(branchtoplot=3, atomtoplot=0, energyvalues=[30]) #wait for input input = raw_input("Finished test2.") return
def test1(): import crystal.UnitCell as UC from crystal.Atom import Atom print "This test should plot some phonon isosurfaces." path = ExcitationSlicer.__file__.strip('__init__.pyc') cellvectors = [[3.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 3.0]] #uc = UC.create_unitcell(cellvectors, [Atom(Z=23), Atom(Z=23)], [(0,0,0), (0.5, 0.5, 0.5)]) uc = UC.UnitCell() uc.setCellVectors(cellvectors) uc.addAtom(Atom(Z=23), (0, 0, 0), '') uc.addAtom(Atom(Z=23), (0.5, 0.5, 0.5), '') print uc myplotter = VTKIsoSurfacePlotter() calc = phonIsoSurfaceCalcor(unitcell=uc, tau=[1.0, 0.0, 0.0], plotter=myplotter) calc.setDataFile(path + 'data/phon_out.pkl') calc.loadPhononData() print "Plot phonon eigen-energy isosurfaces." calc.plotEnergyIsoSurface(branchtoplot=3, energyvalues=[10, 45]) #wait for input input = raw_input("Finished test1.") return
def test_disp100(nq, ne): """Calculates the scattering intensity for phonon dispersions for B2 FeAl along q // [100]. nq = number of q points to calculate. ne = number of e points to calculate.""" uc = UnitCell( ) at1=Atom(symbol='Fe', mass=57) ; pos1=(0.0,0.0,0.0) at2=Atom(symbol='Al') ; pos2=(0.5,0.5,0.5) site1 = Site(pos1, at1) site2 = Site(pos2, at2) uc.addAtom( at1, pos1, "Fe1" ) uc.addAtom( at2, pos2, "Al1" ) print uc kptlist = uc.getMonkhorstPackGrid((20,20,20)).reshape(8000,3) sqecalc = AbInitio.kernelGenerator.SqeCalculator.SqeCalculator(uc, kpoints=kptlist) sqecalc.readIDFeigenvectors(filename='polarizations.idf') sqecalc.readEigenvaluesFromIDFomega2(filename='omega2s.idf') sqecalc._DebyeWallerCalculator._energies = sqecalc._energies sqecalc._DebyeWallerCalculator._polvecs = sqecalc._polvecs estart = 0.0 deltae = 50.0 / ne sqecalc._etransferTol = deltae deltaqx = 3.0 / nq sqecalc._qtransferTolRadius = deltaqx qstart = numpy.array([0.0, 0.0, 0.0]) deltaq = numpy.array([deltaqx, 0.0, 0.0]) sqe = numpy.zeros((nq,ne), dtype='float') for iq in range(nq): for ie in range(ne): qtransfer = qstart + iq * deltaq etransfer = estart + ie * deltae print "Q= %s , E= %s" % (qtransfer, etransfer) sqe[iq,ie] = sqecalc.calcSqeCohCreateAllmodes(qtransfer, etransfer) print "S(Q,E) = ", sqe[iq,ie] pylab.imshow(sqe) pylab.show() end = raw_input() return
def test3(): import crystal.UnitCell as UC from crystal.Atom import Atom path = ExcitationSlicer.__file__.strip('__init__.pyc') cellvectors = [[3.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 3.0]] uc = UC.UnitCell() uc.setCellVectors(cellvectors) uc.addAtom(Atom(Z=23), (0, 0, 0), '') uc.addAtom(Atom(Z=23), (0.5, 0.5, 0.5), '') myslicer = VTKPlaneSlicer() calc = phonIsoSurfaceCalcor(unitcell=uc, tau=[1.0, 0.0, 0.0], slicer=myslicer) calc.setDataFile(path + 'data/phon_out.pkl') calc.loadPhononData() calc.plotIntensityPlaneCut(branchtoplot=3, atomtoplot=0) input = raw_input("Finished test3.") return
def listOfAtom2UnitCell(loa): """Utility to convert a ListOfAtom instance to a UnitCell instance.""" import ASE.ListOfAtoms import ASE.Atom symbols = [x.symbol for x in loa] cartpos = [x.position for x in loa] cellvectors = loa.cell uc = UnitCell() uc.setCellVectors(cellvectors) # note: by default, loa stores cartesian coordinates fracpos = [uc.cartesianToFractional(x) for x in cartpos] for n in range(len(symbols)): atom = Atom(symbol=symbols[n]) uc.addAtom(atom, fracpos[n], '') return uc
import numpy as np from AbInitio.AbiPhon.AbiPhonCalc import AbiPhonCalc from AbInitio.AbiPhon.PhonCalc import PhonCalc from crystal.UnitCell import * from crystal.Atom import * from crystal.crystalIO import converters from AbInitio.vasp.vasp import VASP # create a unit cell: uc = UnitCell( ) vectors = np.array([[2.9, 0, 0],[0, 2.9, 0],[0, 0, 2.9]]) uc.setCellVectors(vectors) at1 = Atom(symbol='Fe', mass=57) ; pos1 = (0.0,0.0,0.0) site1 = Site(pos1, at1) at2 = Atom(symbol='Al') ; pos2 = (0.5,0.5,0.5) site2 = Site(pos2, at2) uc.addSite(site1, "Fe1" ) uc.addSite(site2, "Al1" ) #print uc ### plot the unit cell ### #from ExcitationSlicer.plot3D import plotUnitCell #plotUnitCell(uc) ### create a VASP calculator:
from numpy import random #from inelastic.crystal.UnitCell import * #from inelastic.crystal.crystalIO.converters import * from crystal.UnitCell import * #from crystal.crystalIO.converters import * #from AbInitio.vasp.parsing.Structure import Structure #from AbInitio.vasp.parsing.SystemPM import * #run=XMLSystemPM('vasprun.xml_eq') #struct=run.FINAL_STRUCTURE #uc = p4vaspStruct2UnitCell(struct) #kptgrid = uc.getFracMonkhorstPackGrid((2,2,2)) uc = UnitCell() vectors = [(4.70898, 0, 0), (0, 4.70898, 0), (0, 0, 4.70898)] #vectors = [(1,0,0), (0,1,0), (0,0,1)] uc.setCellVectors(vectors) at1 = Atom(symbol='Si') pos1 = (0, 0, 0) at2 = Atom(symbol='Si') pos2 = (0.5, 0.5, 0.5) at3 = Atom(symbol='V') pos3 = (0.25, 0.50, 0.00) at4 = Atom(symbol='V') pos4 = (0.75, 0.50, 0.00) at5 = Atom(symbol='V') pos5 = (0.00, 0.25, 0.50) at6 = Atom(symbol='V') pos6 = (0.00, 0.75, 0.00)
import crystal.UnitCell as UC from crystal.Atom import * from IsoSurfacePlotter import * from DataSlicer import * import phonIsoSurfaceCalcor as isocalc from phonIsoSurfaceCalcor import * #import sam # <<< not installed on upgrayedd... cellvectors = [[3.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 3.0]] uc = UC.UnitCell() uc.setCellVectors(cellvectors) uc.addAtom(Atom(Z=23), (0, 0, 0), '') uc.addAtom(Atom(Z=23), (0.5, 0.5, 0.5), '') print uc #myplotter = MlabIsoSurfacePlotter() myplotter = VTKIsoSurfacePlotter() myslicer = VTKPlaneSlicer() #calc = phonIsoSurfaceCalcor(unitcell=uc, tau=[1.0,0.0,0.0], plotter=myplotter) calc = phonIsoSurfaceCalcor(unitcell=uc, tau=[0.0, 0.0, 0.0], plotter=myplotter, slicer=myslicer) calc.setDataFile('phon_out.pkl') calc.loadPhononData() #calc.setEnergyGridForBranch(branchindex=3) #calc.setPolarizationGridForBranchAtom(branchindex=3, atomindex=0) #calc.calcIntensityGrid()
from numpy import random #from inelastic.crystal.UnitCell import * #from inelastic.crystal.crystalIO.converters import * from crystal.UnitCell import * #from crystal.crystalIO.converters import * #from AbInitio.vasp.parsing.Structure import Structure #from AbInitio.vasp.parsing.SystemPM import * #run=XMLSystemPM('vasprun.xml_eq') #struct=run.FINAL_STRUCTURE #uc = p4vaspStruct2UnitCell(struct) #kptgrid = uc.getFracMonkhorstPackGrid((2,2,2)) uc = UnitCell() vectors = [(4.70898,0,0), (0,4.70898,0), (0,0,4.70898)] #vectors = [(1,0,0), (0,1,0), (0,0,1)] uc.setCellVectors(vectors) at1 = Atom(symbol='Si') pos1 = (0,0,0) at2 = Atom(symbol='Si') pos2 = (0.5,0.5,0.5) at3 = Atom(symbol='V') pos3 = (0.25, 0.50, 0.00) at4 = Atom(symbol='V') pos4 = (0.75, 0.50, 0.00) at5 = Atom(symbol='V') pos5 = (0.00, 0.25, 0.50) at6 = Atom(symbol='V') pos6 = (0.00, 0.75, 0.00)
import numpy as np from AbInitio.AbiPhon.AbiPhonCalc import AbiPhonCalc from AbInitio.AbiPhon.PhonCalc import PhonCalc from crystal.UnitCell import * from crystal.Atom import * from crystal.crystalIO import converters from AbInitio.vasp.vasp import VASP # create a unit cell: uc = UnitCell() vectors = np.array([[2.9, 0, 0], [0, 2.9, 0], [0, 0, 2.9]]) uc.setCellVectors(vectors) at1 = Atom(symbol='Fe', mass=57) pos1 = (0.0, 0.0, 0.0) site1 = Site(pos1, at1) at2 = Atom(symbol='Al') pos2 = (0.5, 0.5, 0.5) site2 = Site(pos2, at2) uc.addSite(site1, "Fe1") uc.addSite(site2, "Al1") #print uc ### plot the unit cell ### #from ExcitationSlicer.plot3D import plotUnitCell #plotUnitCell(uc) ### create a VASP calculator: