def load(fullfilename): filedir, fileprefix, fileext = path_split(fullfilename) material=Material(fileprefix) file=open(fullfilename, 'r') first_run = 1 while 1: line = file.readline() if not line: break words = line.split() nat = int(words[0]) comment = file.readline() if first_run: first_run = 0 else: material.new_geo() for i in range(nat): line = file.readline() words=line.split() sym=cleansym(words[0]) atno = sym2no[sym] xyz = array(map(float,words[1:4])) material.add_atom(Atom(atno, xyz, sym, sym+str(i))) material.bonds_from_distance() return material
def load(fullfilename): filedir, fileprefix, fileext = path_split(fullfilename) material = Material(fileprefix) file = open(fullfilename, 'r') first_run = True while 1: line = file.readline() if not line: break words = line.split() nat = int(words[0]) comment = file.readline() ax, ay, az, bx, by, bz, cx, cy, cz = [ float(i) for i in comment.split() ] cell = Cell((ax, ay, az), (bx, by, bz), (cx, cy, cz)) if first_run: first_run = False else: material.new_geo() material.set_cell(cell) for i in range(nat): line = file.readline() words = line.split() sym = cleansym(words[0]) atno = sym2no[sym] xyz = array(map(float, words[1:4])) material.add_atom(Atom(atno, xyz, sym, sym + str(i))) material.bonds_from_distance() return material
def load(fullfilename): filedir, fileprefix, fileext = path_split(fullfilename) material = Material(fileprefix) file = open(fullfilename, 'r') nwchem_options = {} geo_pat = re.compile("\s*No\.\s*Tag\s*Charge") molchg_pat = re.compile("\s*Charge\s*:\s*") multip_pat = re.compile("\s*Spin multiplicity:\s*") geos = [] while 1: line = file.readline() if not line: break if geo_pat.search(line): geo = get_geo(file) geos.append(geo) elif molchg_pat.search(line): words = string.split(line) nwchem_options['molchg'] = int(words[2]) elif multip_pat.search(line): words = string.split(line) nwchem_options['multip'] = int(words[2]) # end of main infinite loop file.close() print "Loading %d geometries" % len(geos) for igeo in range(len(geos)): if igeo: material.new_geo() for (atno, xyz) in geos[igeo]: material.add_atom(Atom(atno, xyz)) if len(material.geo.atoms) < 200: material.bonds_from_distance() material.nwchem_options = nwchem_options return material
def load(fullfilename): filedir, fileprefix, fileext = path_split(fullfilename) material=Material(fileprefix) file=open(fullfilename, 'r') first_run = 1 while 1: line = file.readline() if not line: break if not geostart.search(line): continue if first_run: first_run = 0 else: material.new_geo() i = 1 while 1: line = file.readline() if geoend.search(line): break match = atpat.match(line) sym = match.group(1) x = float(match.group(2)) y = float(match.group(3)) z = float(match.group(4)) sym=cleansym(sym) atno = sym2no[sym] xyz = array((x,y,z)) material.add_atom(Atom(atno, xyz, sym, sym+str(i))) i += 1 material.bonds_from_distance() return material
def load(fullfilename): #TODO move this splitting to within Material so the extension can #automatically be the default prefix...then move it into structure filedir, fileprefix, fileext = path_split(fullfilename) from vimm.Material import Material from vimm.Atom import Atom from vimm.Cell import Cell material = Material(fileprefix) material.format = fileext pkl_file = open(fullfilename, 'rb') structure = pickle.load(pkl_file) first_run = 1 if first_run: first_run = 0 else: material.new_geo() for structureAtom in structure: material.add_atom(Atom(structureAtom.Z, structureAtom.xyz_cartn)) aVec, bVec, cVec = structure.lattice.base cell = Cell(aVec, bVec, cVec) material.set_cell(cell) material.bonds_from_distance() return material
def load(fullfilename): gstep = 0 filedir, fileprefix, fileext = path_split(fullfilename) file=open(fullfilename, 'r') # Initialize atom data material = Material(fileprefix) opts = {} material.seqquest_options = opts dconv = 1. # default to Angstroms, which don't need conversion cell = None while 1: line = file.readline() if not line: break line = line.strip() if line == '@=KEYCHAR': continue # ignore other keychars for now elif line == '@DISTANCE UNIT': line = file.readline().strip() if line == 'ANGSTROM': continue elif line == 'BOHR': dconv = bohr2ang else: print "Warning: unknown distance unit ",line elif line == '@DIMENSION': line = file.readline().strip() opts['ndim'] = int(line) elif line == '@NUMBER OF ATOMS': line = file.readline().strip() opts['nat'] = int(line) opts['attypes'] = [] nread = int(ceil(opts['nat']/20.)) for i in range(nread): line = file.readline().strip() opts['attypes'].extend(map(int,line.split())) assert len(opts['attypes']) == opts['nat'] elif line == '@TYPES': line = file.readline().strip() opts['ntyp'] = int(line) opts['types'] = [] for i in range(opts['ntyp']): line = file.readline().strip() opts['types'].append(cleansym(line)) elif line == '@CELL VECTORS': line = file.readline() axyz = map(float,line.split()) line = file.readline() bxyz = map(float,line.split()) line = file.readline() cxyz = map(float,line.split()) if abs(dconv-1) > 1e-4: # careful when comparing floats axyz = axyz[0]*dconv,axyz[1]*dconv,axyz[2]*dconv bxyz = bxyz[0]*dconv,bxyz[1]*dconv,bxyz[2]*dconv cxyz = cxyz[0]*dconv,cxyz[1]*dconv,cxyz[2]*dconv cell = Cell(axyz,bxyz,cxyz) elif line == '@GSTEP': line = file.readline().strip() gstep = int(line) elif line == '@COORDINATES': atoms = [] for i in range(opts['nat']): line = file.readline() xyz = map(float,line.split()) if abs(dconv-1) > 1e-4: # careful when comparing floats xyz = xyz[0]*dconv,xyz[1]*dconv,xyz[2]*dconv isym = opts['attypes'][i] sym = opts['types'][isym-1] atoms.append((sym,xyz)) if gstep > 1: material.new_geo() for i in range(opts['nat']): sym,xyz = atoms[i] atno = sym2no[sym] xyz = array(xyz) material.add_atom(Atom(atno,xyz)) if cell: material.set_cell(cell) elif line == '@ESCF': line = file.readline().strip() escf = float(line) # Consider saving these for plotting elif line == '@FORCES': forces = [] for i in range(opts['nat']): line = file.readline() forces.append(map(float,line.split())) elif line == '@FMAX': line = file.readline().strip() fmax = float(line) elif line == '@FRMS': line = file.readline().strip() frms = float(line) else: print "Unknown line ",line material.bonds_from_distance() return material
def load(fullfilename): filedir, fileprefix, fileext = path_split(fullfilename) material = Material(fileprefix) from Scientific.IO.NetCDF import NetCDFFile file = NetCDFFile(fullfilename, 'r') allDimNames = file.dimensions.keys() print 'allDimNames', allDimNames vars = file.variables.keys() print 'vars', vars if file.variables.has_key('dsf'): sf = file.variables['dsf'].getValue() #numpy array zLabel = 'S(Q,Omega) (a.u.)' elif file.variables.has_key('sf'): sf = file.variables['sf'].getValue() #numpy array zLabel = 'F(Q,t) (a.u.)' print sf q = file.variables['q'].getValue() print 'q', q if file.variables.has_key('frequency'): timeOrFreq = file.variables['frequency'].getValue() #numpy array yLabel = 'Omega (1/ps)' elif file.variables.has_key('time'): timeOrFreq = file.variables['time'].getValue() #numpy array yLabel = 'Time (ps)' print 'timeOrFreq', timeOrFreq material.new_geo() #triangulate and plot the surface #from vimm.Shapes import Triangles triangleCoords = [] #Triangles((1.,0.,1.)) #start across the first axis as x xLen, yLen = sf.shape # for i in range(xLen): # for j in range(yLen): # triangleCoords.append((q[i],timeOrFreq[j],sf[i,j])) for i in range(xLen - 1): for j in [0, 1]: #range(yLen-1): #use the spacing given in the q and timeOrFrequency #triangulate each of the squares in the grid #lower triangle #3\ #| \ #1--2 triangleCoords.append(((q[i], timeOrFreq[j], sf[i, j]), (q[i + 1], timeOrFreq[j], sf[i + 1, j]), (q[i], timeOrFreq[j + 1], sf[i, j + 1]))) #upper triangle #3--2 # \ | # \1 triangleCoords.append( ((q[i + 1], timeOrFreq[j], sf[i + 1, j]), (q[i + 1], timeOrFreq[j + 1], sf[i + 1, j + 1]), (q[i], timeOrFreq[j + 1], sf[i, j + 1]))) material.geo.surface = triangleCoords #add the axes to the plot--assume orthogonal for now aLen = q[-1] - q[0] bLen = timeOrFreq[-1] - timeOrFreq[0] cLen = sf.max() - sf.min() a = (aLen, 0, 0) b = (0, bLen, 0) c = (0, 0, cLen) # scale the axes so they are roughly equal scaleA = 1 / aLen scaleB = 1 / bLen scaleC = 2 / cLen #C axis is half as large from vimm.Cell import Cell cell = Cell(a, b, c, scaleA=scaleA, scaleB=scaleB, scaleC=scaleC) cell.aLabel = 'Q (1/Ang)' cell.bLabel = yLabel cell.cLabel = zLabel # add tick mark labels /data point labels to the plot cell.tickmarks = { 'A': [(qPoint, 0, 0) for qPoint in q], 'B': [(0, timeOrFreqPoint, 0) for timeOrFreqPoint in timeOrFreq] } material.set_cell(cell) return material
def load(fullfilename): filedir, fileprefix, fileext = path_split(fullfilename) file = open(fullfilename, 'r') # Initialize atom data material = Material(fileprefix) element = [] # Initialize element variable to be appended timestamp = 1 nat = None cell = None lattice_coords = False scale = 1. scalez = 1. conv_to_ang = True while 1: line = file.readline() if not line: break if p_atomtype.search(line): # From the headerfile get the number of atom types line = file.readline() numberoftypes = int(line) elif p_coord_type.search(line): line = file.readline() line = line.strip().lower() if line == 'lattice': lattice_coords = True elif p_to_lattice.search(line): raise "Quest to_lattice flags not currently supported" elif p_scale.search(line): line = file.readline() scale = float(line.strip()) elif p_scalez.search(line): line = file.readline() scalez = float(line.strip()) # Using the atom type number, set the atom names elif p_atomfile.search(line): line = file.readline() words = string.split(line) atomname = cleansym(words[0]).capitalize() #atomname,atomext = path.splitext(words[0]) #atomname = string.capitalize(atomname) # Captitalize the element.append(atomname) # first letter elif p_nat.search(line): line = file.readline() words = string.split(line) nat = int(words[0]) # Read in the initial geometry data elif p_geometry.search(line): for i in range(nat): line = file.readline() words = string.split(line) num = int(words[0]) try: type = element[int(words[1]) - 1] #Set the type atno = sym2no[type] except: # Fallback for when atoms are specified with symbols atno = sym2no[words[1]] x, y, z = [float(i) for i in words[2:5]] #print x,y,z if lattice_coords: converter = cell.lat2cart_factory() x, y, z = converter(x, y, z) #print x,y,z elif conv_to_ang: x, y, z = [bohr2ang * i for i in [x, y, z]] #print x,y,z xyz = array((x, y, z)) material.add_atom(Atom(atno, xyz)) if cell: material.set_cell(cell) elif p_newgeo.search(line): comment = file.readline() material.new_geo() for i in range(nat): line = file.readline() words = string.split(line) num = int(words[0]) try: type = element[int(words[1]) - 1] #Set the type atno = sym2no[type] except: # Fallback for when atoms are specified with symbols atno = sym2no[words[1]] x, y, z = [float(i) for i in words[2:5]] #print x,y,z if lattice_coords: converter = cell.lat2cart_factory() x, y, z = converter(x, y, z) #print x,y,z elif conv_to_ang: x, y, z = [bohr2ang * i for i in [x, y, z]] #print x,y,z xyz = array((x, y, z)) material.add_atom(Atom(atno, xyz)) if cell: material.set_cell(cell) elif p_cell.search(line): line = file.readline() words = string.split(line) ax, ay, az = [float(i) for i in words[:3]] if conv_to_ang: ax, ay, az = [bohr2ang * i for i in [ax, ay, az]] line = file.readline() words = string.split(line) bx, by, bz = [float(i) for i in words[:3]] if conv_to_ang: bx, by, bz = [bohr2ang * i for i in [bx, by, bz]] line = file.readline() words = string.split(line) cx, cy, cz = [float(i) for i in words[:3]] if conv_to_ang: cx, cy, cz = [bohr2ang * i for i in [cx, cy, cz]] cell = Cell((ax, ay, az), (bx, by, bz), (cx, cy, cz), scale=scale, scalez=scalez) file.close() material.bonds_from_distance() return material