Exemplo n.º 1
0
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
Exemplo n.º 2
0
def load(fullfilename):
    filedir, fileprefix, fileext = path_split(fullfilename)
    material = Material(fileprefix)
    file = open(fullfilename, 'r')

    atoms = []
    bfs = []
    orbs = []

    mode = None

    for line in file.readlines():
        if atpat.search(line): mode = 'atoms'
        elif bfpat.search(line): mode = 'bfs'
        elif orbpat.search(line): mode = 'orbs'
        elif mode == 'atoms': atoms.append(line)
        elif mode == 'bfs': bfs.append(line)
        elif mode == 'orbs': orbs.append(line)
        else: print '? ', line,

    for line in atoms:
        words = line.split()
        if len(words) < 6: continue

        atno = int(words[2])
        xyz = map(float, words[3:6])
        material.add_atom(Atom(atno, array(xyz)))
    material.bonds_from_distance()
    material.geo.basis = parse_basis(bfs)
    material.geo.orbs = parse_orbs(orbs)
    return material
Exemplo n.º 3
0
def save(filename, material):
    dir, prefix, ext = path_split(filename)
    atoms = material.get_atom_list()
    cell = material.get_cell()
    flines = ["<?xml version=\"1.0\" ?>"]
    flines.append("<cml title=\"%s\">" % prefix)
    flines.append("<molecule id=\"%s\">" % prefix)
    if cell:
        ax, ay, az = cell.axyz
        bx, by, bz = cell.bxyz
        cx, cy, cz = cell.cxyz
        flines.append(" <crystal>")
        flines.append(
            "  <floatArray convention=\"PMP\" title=\"a\">%f %f %f</floatArray>"
            % (ax, ay, az))
        flines.append(
            "  <floatArray convention=\"PMP\" title=\"b\">%f %f %f</floatArray>"
            % (bx, by, bz))
        flines.append(
            "  <floatArray convention=\"PMP\" title=\"c\">%f %f %f</floatArray>"
            % (cx, cy, cz))
        flines.append(" </crystal>")

    flines.append(" <atomArray>")
    for atom in atoms:
        x, y, z = atom.get_position()
        flines.append(
            "  <atom id=\"%s\" elementType=\"%s\" x3=\"%f\" y3=\"%f\" z3=\"%f\"/>"
            % (atom.get_label(), atom.get_symbol(), x, y, z))
    flines.append(" </atomArray>")
    flines.append("</molecule>")
    flines.append("</cml>\n")

    open(filename, 'w').write("\n".join(flines))
    return
Exemplo n.º 4
0
def load(fullfilename):
    filedir, fileprefix, fileext = path_split(fullfilename)
    material = Material(fileprefix)
    file = open(fullfilename, 'r')

    line = file.readline()
    title = line.strip()
    line = file.readline()
    title2 = line.strip()
    line = file.readline()
    title3 = line.strip()

    line = file.readline()
    natoms = int(line[:3])
    nbonds = int(line[3:6])

    # Note: I'm skipping the H information here, which is
    #  typically given in fields 5-
    for i in range(natoms):
        line = file.readline()
        words = line.split()
        xyz = array(map(float, words[:3]))
        sym = cleansym(words[3])
        atno = sym2no[sym]
        material.add_atom(Atom(atno, xyz, sym, sym + str(i)))
    atoms = material.get_atoms()
    for i in range(nbonds):
        line = file.readline()
        words = line.split()
        # bond order is the third field, which I'm ignoring
        iat, jat, iorder = map(int, words[:3])
        material.add_bond(Bond(atoms[iat - 1], atoms[jat - 1], iorder))
    return material
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
def load(fullfilename):
    filedir, fileprefix, fileext = path_split(fullfilename)
    material = Material(fileprefix)
    file = open(fullfilename, 'r')

    line = file.readline()
    title = line.strip()

    line = file.readline()
    natoms, nbonds = map(int, line.split())
    for i in range(natoms):
        line = file.readline()
        words = line.split()
        xyz = array(map(float, words[:3]))
        sym = cleansym(words[3])
        atno = sym2no[sym]
        material.add_atom(Atom(atno, xyz, sym, sym + str(i)))
    atoms = material.get_atoms()
    for i in range(nbonds):
        line = file.readline()
        words = line.split()
        # I think order is the third one, but I'm not sure
        iat, jat, iorder = map(int, words[:3])
        material.add_bond(Bond(atoms[iat - 1], atoms[jat - 1], iorder))
    return material
Exemplo n.º 8
0
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
Exemplo n.º 9
0
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
Exemplo n.º 10
0
def load(fullfilename):
    filedir, fileprefix, fileext = path_split(fullfilename)
    material=Material(fileprefix)
    file=open(fullfilename, 'r')

    hatpat = re.compile('HETATM')
    atpat = re.compile('^ATOM')
    conpat = re.compile('^CONECT')
    ordpat = re.compile('^ORDER')
    endpat = re.compile('^END')
    ucpat = re.compile('^CRYSTX')

    bonds = {}
    orders = {}
    iat = 0
    for line in open(fullfilename):
        if hatpat.search(line) or atpat.search(line):
            d1,i,d2,d3,d4,d5,x,y,z,attype,d6,d7,q = read(line,atom_format)
            xyz = array([x,y,z])
            sym = cleansym(attype)
            atno = sym2no[sym]
            atom = Atom(atno,xyz,sym,sym+str(iat))
            atom.fftype = attype # save just in case
            material.add_atom(atom)
            iat += 1
        elif conpat.search(line):
            ats = map(int,line[6:].split())
            index = ats[0]-1
            bonds[index] = [atj-1 for atj in ats[1:]]
            orders[index] = [1]*(len(ats)-1)
        elif ordpat.search(line):
            ords = map(int,line[6:].split())
            index = ords[0]-1
            orders[index] = ords[1:]
        elif ucpat.search(line):
            words = line.split()
            a,b,c,alpha,beta,gamma = map(float,words[1:7])
            axyz,bxyz,cxyz = abcabg2abc(a,b,c,alpha,beta,gamma)
            cell = Cell(axyz,bxyz,cxyz)
            material.set_cell(cell)
    atoms = material.get_atoms()
    #print len(atoms)," atoms loaded"
    for iat in bonds.keys():
        bond_partners = bonds[iat]
        bond_orders = orders[iat]
        for jat,ij_order in zip(bond_partners,bond_orders):
            if jat > iat: material.add_bond(Bond(atoms[iat],atoms[jat],
                                                 ij_order))
    return material
Exemplo n.º 11
0
def save(fullfilename, material):
    filedir, fileprefix, fileext = path_split(fullfilename)
    file = open(fullfilename, 'w')

    towhee = material.towhee_options

    if towhee.get_iformat() == "Towhee":
        save_towhee_file(file, towhee)
    elif towhee.get_iformat() == "LAMMPS":
        # Close towhee_input file and open lammps_data
        save_lammp_file(file, towhee)
    elif towhee.get_iformat() == "Database":
        save_database_file(file, towhee)
    else:
        print "Invalid towhee format"

    return
Exemplo n.º 12
0
def load(fullfilename):
    filedir, fileprefix, fileext = path_split(fullfilename)
    material=Material(fileprefix)
    
    try:
        from matter.Structure import Structure
        st = Structure()
        st.read(fullfilename)
        for i,atom in enumerate(st):
            Z = atom.Z
            xyz_cartn = atom.xyz_cartn
            sym = atom.symbol
            material.add_atom(Atom(Z, xyz_cartn, sym, sym+str(i)))
        material.bonds_from_distance()
        lvs = st.lattice.base
        cell = Cell(lvs[0],lvs[1],lvs[2])
        material.set_cell(cell)
        return material
    except:
        print 'Vimm needs matter package from pypi to open cif files'
        return
Exemplo n.º 13
0
def load(fullfilename):
    filedir, fileprefix, fileext = path_split(fullfilename)
    file = open(fullfilename, 'r')
    #
    # Initialize atom data
    #
    material = Material(fileprefix)
    material.name = fileprefix
    material.towhee_options = None
    #
    # These 2 are at the beginning of every file format
    # Random Number Seed
    #
    line = file.readline()
    line = file.readline()
    randomseed = int(line.strip())
    #
    # Input Format
    #
    line = file.readline()
    templine = file.readline()
    line = templine.strip()
    iformat = line[1:-1]

    # 3 different input formats
    if iformat == "Towhee":
        towhee = load_towhee_file(file)
        if towhee:
            towhee.set_randomseed(randomseed)
    elif iformat == "LAMMPS":
        # Close towhee_input file and open lammps_data
        file.close()
        towhee = load_lammp_file(filedir)
    elif iformat == "Database":
        towhee = load_database_file(file, filedir)
    else:
        print "Invalid format: " + iformat

    material.towhee_options = towhee
    return material
Exemplo n.º 14
0
def load(fullfilename):
    filedir, fileprefix, fileext = path_split(fullfilename)
    material = Material(fileprefix)

    parser = CMLParser()
    geos = parser.process(fullfilename)

    molecule = geos[0]
    atoms = molecule.atoms
    cell = molecule.cell
    nat = len(atoms)

    for i in range(nat):
        sym, pos = atoms[i]
        pos = array(pos)
        atno = sym2no[sym]
        material.add_atom(Atom(atno, pos, sym, sym + str(i)))
    if cell:
        the_cell = Cell(cell[0], cell[1], cell[2])
        material.set_cell(the_cell)
    material.bonds_from_distance()
    return material
Exemplo n.º 15
0
def load(fullfilename):
    filedir, fileprefix, fileext = path_split(fullfilename)
    material=Material(fileprefix)

    curresnum = None
    curres = None
    locator = None
    residues = []
    for line in open(fullfilename):
        tag = line[:6].strip()
        if tag == 'ATOM' or tag == 'HETATM':
            loctag = line[16:17].strip()
            resnum = int(line[22:26])
            modifyer = line[26].strip()
            restag = line[18:21].strip()
            x = float(line[30:38])
            y = float(line[38:46])
            z = float(line[46:54])
            xyz = array([x,y,z])
            try:
                sym = line[13:15].strip()
                sym = symconv[sym]
                atno = sym2no[sym]
            except:
                sym = line[12:15].strip()
                atno = sym2no[sym]
            if loctag:
                if not locator: locator = loctag
            if loctag and loctag != locator: continue
            if modifyer: continue  # skip residue #25B if we already have #25
            material.add_atom(Atom(atno,xyz))
        elif tag == 'CRYST1':
            words = line.split()
            a,b,c,alpha,beta,gamma = map(float,words[1:7])
            #finish
    material.bonds_from_distance()
    return material
Exemplo n.º 16
0
def save(fullfilename, material):
    filedir, fileprefix, fileext = path_split(fullfilename)
    file = open(fullfilename, 'w')

    opts = getattr(material, 'seqquest_options', {})
    cell = material.get_cell()

    if opts.has_key('lvlout'):
        file.write('output level\n%d\n' % opts['lvlout'])

    if opts.has_key('dosetup'):
        if not opts['dosetup']: file.write('no setup\n')
    else: file.write('do setup\n')

    if opts.has_key('doiters'):
        if not opts['doiters']: file.write('no iters\n')
    else: file.write('do iters\n')

    if opts.has_key('doforce'):
        if opts['doforce']: file.write('do force\n')
    else: file.write('no force\n')

    if opts.has_key('dorelax'):
        if opts['dorelax']: file.write('do relax\n')
    else: file.write('no relax\n')

    if opts.has_key('docell'):
        if opts['docell']: file.write('do cell\n')
    else: file.write('no cell\n')

    if opts.has_key('doneb'):
        if opts['doneb']: file.write('do neb\n')
        else: file.write('no neb\n')

    if opts.has_key('domd'):
        if opts['domd']: file.write('do md\n')
        else: file.write('no md\n')

    if opts.has_key('dopost'):
        if opts['dopost']: file.write('do post\n')
        else: file.write('no post\n')

    if opts.has_key('doblas3'):
        if opts['doblas3']: file.write('do blas3\n')
        else: file.write('no blas3\n')

    file.write('setup data\n')

    if opts.has_key('title'):
        lines = opts['title']
        file.write('title%d\n' % len(lines))
        for line in lines:
            file.write('%s\n' % line)
    else:
        file.write('title\nSeqquest input file generated by Icarus\n')

    if opts.has_key('dft_func'):
        file.write('functional\n%s\n' % opts['dft_func'])

    if opts.has_key('spinpol'):
        file.write('spin polarization\n%d\n' % opts['spinpol'])

    if opts.has_key('efield'):
        file.write('efield\n%f %f %f\n' % opts['efield'])

    if opts.has_key('dielec'):
        file.write('dielectric constant\n%f\n' % opts['dielec'])

    ndim = opts.get('ndim', 3)
    file.write('dimensions of system (0=cluster ... 3=bulk)\n%d\n' % ndim)

    if opts.has_key('coords'):
        file.write('coordinates\n%s\n' % opts['coords'])

    if opts.has_key('scalep'):
        file.write('scalep\n%f\n' % opts['scalep'])
    if opts.has_key('scaleu'):
        file.write('scaleu\n%f\n' % opts['scaleu'])
    if opts.has_key('scalex'):
        file.write('scalex\n%f\n' % opts['scalex'])
    if opts.has_key('scaley'):
        file.write('scaley\n%f\n' % opts['scaley'])
    if opts.has_key('scalez'):
        file.write('scalez\n%f\n' % opts['scalez'])

    if opts.has_key('strain'):
        file.write('strain\n%f %f %f\n%f %f %f\n%f %f %f\n' % opts['strain'])
    if opts.has_key('strfac'):
        file.write('strfac\n%f\n' % opts['strfac'])

    ax, ay, az = cell.axyz
    ax, ay, az = ax / bohr2ang, ay / bohr2ang, az / bohr2ang
    bx, by, bz = cell.bxyz
    bx, by, bz = bx / bohr2ang, by / bohr2ang, bz / bohr2ang
    cx, cy, cz = cell.cxyz
    cx, cy, cz = cx / bohr2ang, cy / bohr2ang, cz / bohr2ang
    file.write('primitive lattice vectors\n%f %f %f\n%f %f %f\n%f %f %f\n' %
               (ax, ay, az, bx, by, bz, cx, cy, cz))

    grid = opts.get('griddim', None)
    if not grid:
        a = sqrt(ax * ax + ay * ay + az * az)
        b = sqrt(bx * bx + by * by + bz * bz)
        c = sqrt(cx * cx + cy * cy + cz * cz)
        grid = (int(a / 0.3), int(b / 0.3), int(c / 0.3))
    file.write('grid dimensions\n%d %d %d\n' % tuple(grid))

    if opts.has_key('nearby'):
        file.write('nearby\n%d\n' % opts['nearby'])

    atoms = material.get_atom_list()
    nat = len(atoms)

    if opts.has_key('types'):
        types = opts['types']
    else:
        # Using a list for types here; replace this with a dict
        # if this becomes slow, since a dict is faster for
        # membership testing. Maybe even a set?
        types = []
        opts['types'] = types
        for i in range(nat):
            sym = atoms[i].get_symbol()
            if sym not in types: types.append(sym)

    ntypes = len(types)
    file.write('atom types\n%d\n' % ntypes)
    typeindex = {}
    for i in range(ntypes):
        fname = types[i]
        sym = cleansym(fname)
        typeindex[sym] = i + 1
        if fname[:-4] != '.atm': fname = fname + '.atm'
        file.write('atom file\n%s\n' % fname)

    file.write('number of atoms in unit cell\n%d\n' % nat)
    file.write('atom, type, position vector\n')
    for i in range(nat):
        atom = atoms[i]
        sym = atom.get_symbol()
        x, y, z = atom.get_position()
        x, y, z = x / bohr2ang, y / bohr2ang, z / bohr2ang
        file.write('%d %d %14.10f %14.10f %14.10f\n' %
                   (i + 1, typeindex[sym], x, y, z))

    if opts.has_key('to_lat'):
        file.write('to_lattice\n')
    elif opts.has_key('to_car'):
        file.write('to_cartesian\n')

    if opts.has_key('dorig'):
        file.write('origin\n%f %f %f\n' % opts['dorig'])

    if opts.has_key('rchrg'):
        file.write('wigner seitz origin\n%f %f %f\n' % opts['rchrg'])

    if opts.has_key('rsym'):
        file.write('symmetry origin\n%f %f %f\n' % opts['rsym'])

    if opts.has_key('kgrid'):
        file.write('kgrid\n%d %d %d\n' % tuple(opts['kgrid']))
    elif opts.has_key('khex'):
        file.write('kgrid\n%d %d\n' % tuple(opts['khex']))
    else:
        ndim = opts.get('ndim', 3)
        if ndim == 3: file.write('kgrid\n%d %d %d\n' % (1, 1, 1))
        elif ndim == 2: file.write('kgrid\n%d %d %d\n' % (1, 1, 0))
        elif ndim == 1: file.write('kgrid\n%d %d %d\n' % (1, 0, 0))

    if opts.has_key('nk'):
        file.write('n bloch vectors\n%d\n' % opts['nk'])
        # skipping scalin, lattic, cartes
    if opts.has_key('bloch vectors\n'):
        bvecs = opts['bloch_vecs']
        for bvec in bvecs:
            file.write('%f %f %f\n' % bvec)

    if opts.has_key('nsymi'):
        file.write('symops\n%d\n' % opts['nsymi'])
        file.write('definition of symmetry operations\n')
        symvecs = opts['symvecs']
        for symvec in symvecs:
            file.write('%4d %10.5f %10.5f %10.5f  %10.5f %10.5f %10.5f\n' %
                       symvec)

    file.write('end setup phase data\n')

    file.write('run phase input data\n')

    if opts.has_key('doflag'):
        if opts['doflag']: file.write('do flag\n')
        else: file.write('no flag\n')

    if opts.has_key('itstart'):
        file.write('first iteration\n%d\n' % opts['itstart'])
    if opts.has_key('itstop'):
        file.write('last iteration\n%d\n' % opts['itstop'])
    if opts.has_key('nhiste'): file.write('history\n%d\n' % opts['nhiste'])
    if opts.has_key('itrst'): file.write('restart\n%d\n' % opts['itrst'])
    if opts.has_key('nstate'): file.write('states\n%d\n' % opts['nstate'])
    if opts.has_key('etemp'): file.write('temperature\n%f\n' % opts['etemp'])
    if opts.has_key('scfblnd'):
        file.write('blend percent\n%f\n' % opts['scfblnd'])
    if opts.has_key('scfbl2'): file.write('scfbl2\n%f\n' % opts['scfbl2'])
    if opts.has_key('scfconv'):
        file.write('convergence criteria\n%f\n' % opts['scfconv'])
    if opts.has_key('alfast'): file.write('alfast\n%f\n' % opts['alfast'])

    if opts.has_key('convii'): file.write('cutii \n%f\n' % opts['convii'])
    if opts.has_key('convsl'): file.write('cutslo\n%f\n' % opts['convsl'])
    if opts.has_key('conv2s'): file.write('cut2s \n%f\n' % opts['conv2s'])
    if opts.has_key('cutset'): file.write('cutset\n%f\n' % opts['cutset'])
    if opts.has_key('cutfrc'): file.write('cutfrc\n%f\n' % opts['cutfrc'])
    if opts.has_key('convgr'): file.write('cutgrd\n%f\n' % opts['convgr'])
    if opts.has_key('conv1c'): file.write('cut1c \n%f\n' % opts['conv1c'])

    dowritegeo = opts.get('write_geo_sect', False)
    if dowritegeo:
        file.write('geometry parameters\n')
        if opts.has_key('geo_dorelax'): file.write('relax\n')

        if opts.has_key('relax_range'):
            file.write('grelax\n%d %d\n' % opts['relax_range'])
        if opts.has_key('fixed_range'):
            file.write('gfixed\n%d %d\n' % opts['fixed_range'])
        if opts.has_key('only_relax'):
            file.write('only relax\n%d\n' % opts['only_relax'])
        if opts.has_key('relax_frame'):
            file.write('frame for relaxation\n%d %d %d\n' %
                       opts['relax_frame'])
        if opts.has_key('defect'):
            file.write('defect\n%d\n' % opts['defect'])
        if opts.has_key('gblend'):
            file.write('gblend\n%f\n' % opts['gblend'])
        if opts.has_key('gconv'):
            file.write('gconv \n%f\n' % opts['gconv'])
        if opts.has_key('gstart'):
            file.write('gstart\n%d\n' % opts['gstart'])
        if opts.has_key('gsteps'):
            file.write('gsteps\n%d\n' % opts['gsteps'])
        if opts.has_key('nhistg'):
            file.write('ghistory\n%d\n' % opts['nhistg'])
        if opts.has_key('igges'):
            igges = opts['igges']
            if igges == 0:
                file.write('no ges\n')
            else:
                file.write('guess \n%d\n' % igges)
        if opts.has_key('gmethod'):
            file.write('gmethod\n%s\n' % opts['gmethod'])
        if opts.has_key('gtstep'):
            file.write('timestep\n%f\n' % opts['gtstep'])
        file.write('end geometry parameters\n')

    dowritecell = opts.get('write_cell_sect', False)
    if dowritecell:
        file.write('cell paramters\n')
        if opts.has_key('maxucsteps'):
            file.write('ucstep\n%d\n' % opts['maxucsteps'])
        if opts.has_key('ucconv'):
            file.write('uc_convergence\n%f\n' % opts['ucconv'])
        if opts.has_key('pressure'):
            file.write('pressure\n%f\n' % opts['pressure'])
        if opts.has_key('uniaxial'):
            file.write('uniaxial pressure\n%f %f %f\n' % opts['uniaxial'])
        if opts.has_key('stress'):
            file.write('stress\n')
            stress = opts['stress']
            for vec in stress:
                file.write('%f %f %f\n' % vec)
        if opts.has_key('nhistuc'):
            file.write('uchistory\n%d\n' % opts['nhistuc'])
        if opts.has_key('ucmeth'):
            file.write('ucmethod\n%s\n' % opts['ucmeth'])
        if opts.has_key('strsbroy'):
            file.write('str_br\n%f\n' % opts['strsbroy'])
        if opts.has_key('strnmax'):
            file.write('max_strain\n%f\n' % opts['strnmax'])
        if opts.has_key('cell_f'):
            file.write('cell_f\n%f\n' % opts['cell_f'])
        if opts.has_key('bmod'):
            file.write('bulk_modulus\n%f\n' % opts['bmod'])
        if opts.has_key('ucblend'):
            file.write('uc_blend\n%f\n' % opts['ucblend'])
        file.write('end cell parameters\n')
    file.write('end of run phase data\n')

    if opts.has_key('domd') and opts['domd']:
        file.write('md data\n')
        if opts.has_key('mdtemp'):
            file.write('temperature\n%f\n' % opts['mdtemp'])
        if opts.has_key('ntstep'):
            file.write('time steps\n%d\n' % opts['ntstep'])
        if opts.has_key('neqsteps'):
            file.write('equil steps\n%d\n' % opts['neqsteps'])
        if opts.has_key('md_dt'):
            file.write('step size\n%f\n' % opts['md_dt'])
        if opts.has_key('mdtype'):
            file.write('md type\n%s\n' % opts['mdtype'])
        file.write('end md data\n')
    # done!
    return
Exemplo n.º 17
0
def load(fullfilename,**kwargs):
    # Keyword args
    VERBOSE = kwargs.get('VERBOSE',False)
    
    filedir, fileprefix, fileext = path_split(fullfilename)
    material=Material(fileprefix)

    # Pass 1: check ndtset
    ndtset = 0
    natom = 0
    ntypat = 0
    dt = 1
    iter = abinit_tokenizer(open(fullfilename),**kwargs)
    while 1:
        try:
            word = iter.next()
        except:
            break
        if word == 'ndtset':
            ndtset = int(iter.next())
            if ndtset > 1:
                print "Multiple data sets found. Reading only the first"
                # If you want to select a particular data set, pop
                #  up a dialog box here and ask which one you
                #  want to load.
                # Also need to put code in here so that you don't
                #  get the dialog box twice, such as dt_selected
                #  boolean
        elif word == 'natom':
            natom = int(iter.next())
        elif word == 'ntypat':
            ntypat = int(iter.next())
            
    # Pass 2: get remaining info
    xangst = None
    xred = None
    xcart = None
    znucl = None
    typat = None
    rprim = None
    acell = None
    angdeg = None
    iter = abinit_tokenizer(open(fullfilename),**kwargs)
    while 1:
        try:
            word = iter.next()
        except:
            break
        if word == 'xangst' or word == 'xangst%d' % dt:
            xangst = get_natom3(iter,natom)
        elif word == 'xred' or word == 'xred%d' % dt:
            xred = get_natom3(iter,natom)
        elif word == 'xcart' or word == 'xcart%d' % dt:
            xcart = get_natom3(iter,natom)
        elif word == 'znucl':
            znucl = [int(float(i)) for i in nextn(iter,ntypat)]
        elif word == 'typat':
            typat = [int(i) for i in nextn(iter,natom)]
        elif word == 'acell' or word == 'acell%d' % dt:
            acell = [float(i) for i in nextn(iter,3)]
        elif word == 'rprim' or word == 'rprim%d' % dt:
            rprim = [float(i) for i in nextn(iter,9)]
        elif word == 'angdeg' or word == 'angdeg%d' % dt:
            angdeg = [float(i) for i in nextn(iter,3)]

    # Done parsing
    if VERBOSE:
        print "natom = ",natom
        print "ntypat = ",ntypat
        print "znucl = ",znucl
        print "typat = ",typat
        print "xcart = ",xcart
        print "xred = ",xred
        print "xangst = ",xangst
        print "acel = ",acell
        print "rprim = ",rprim
        print "angdeg = ",angdeg

    # Build the unit cell. Precedence is rprim > angdeg
    if not acell: acell = [1,1,1]
    acell = [bohr2ang*i for i in acell] # Convert acell to Angstrom
    
    if rprim:
        ax,ay,az,bx,by,bz,cx,cy,cz = rprim
        cell = Cell( (acell[0]*ax,acell[0]*ay,acell[0]*az),
                     (acell[1]*bx,acell[1]*by,acell[1]*bz),
                     (acell[2]*cx,acell[2]*cy,acell[2]*cz))
    else:
        if not angdeg:
            angdeg = [90.,90.,90.]
        axyz,bxyz,cxyz = abcabg2abc(acell[0],acell[1],acell[2],
                                    angdeg[0],angdeg[1],angdeg[2])
        cell = Cell(axyz,bxyz,cxyz)
    material.set_cell(cell)
    
    # Build the atom list. Precedence is xred > xangst > xcart
    if xred:
        A,B,C = cell.abc()
        for i in range(natom):
            atno = znucl[typat[i-1]-1]
            xr,yr,zr = xred[i]
            xyz = xr*A + yr*B + zr*C
            material.add_atom(Atom(atno,xyz))
    elif xangst:
        for i in range(natom):
            atno = znucl[typat[i-1]-1]
            material.add_atom(Atom(atno,xangst[i]))
    elif xcart:
        for i in range(natom):
            atno = znucl[typat[i-1]-1]
            xyz = [bohr2ang*a for a in xcart[i]]
            material.add_atom(Atom(atno,xyz))
    else:
        raise "Abinit Input: must specify xred, xangst, or xcart"
    material.bonds_from_distance()
    return material
Exemplo n.º 18
0
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
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
Exemplo n.º 20
0
def load(fullfilename):
    filedir, fileprefix, fileext = path_split(fullfilename)
    file = open(fullfilename, 'r')

    # Initialize atom data
    material = Material(fileprefix)
    opts = {}
    material.seqquest_options = opts

    line = file.readline()  # start reading

    # Read in the run options
    while 1:
        if line[:8] == 'output l':
            line = file.readline()
            opts['lvlout'] = int(line.strip())
            line = file.readline()
        elif line[:8] == 'do setup':
            opts['dosetup'] = True
            line = file.readline()
        elif line[:8] == 'no setup':
            opts['dosetup'] = False
            line = file.readline()
        elif line[:8] == 'do iters':
            opts['doiters'] = True
            line = file.readline()
        elif line[:8] == 'no iters':
            opts['doiters'] = False
            line = file.readline()
        elif line[:8] == 'do force':
            opts['doforce'] = True
            line = file.readline()
        elif line[:8] == 'no force':
            opts['doforce'] = False
            line = file.readline()
        elif line[:8] == 'do relax':
            opts['dorelax'] = True
            line = file.readline()
        elif line[:8] == 'no relax':
            opts['dorelax'] = False
            line = file.readline()
        elif line[:7] == 'do cell':
            opts['docell'] = True
            line = file.readline()
        elif line[:7] == 'no cell':
            opts['docell'] = False
            line = file.readline()
        elif line[:6] == 'do neb':
            opts['doneb'] = True
            line = file.readline()
        elif line[:6] == 'no neb':
            opts['doneb'] = False
            line = file.readline()
        elif line[:5] == 'do md':
            opts['domd'] = True
            line = file.readline()
        elif line[:5] == 'no md':
            opts['domd'] = False
            line = file.readline()
        elif line[:7] == 'do post':
            opts['dopost'] = True
            line = file.readline()
        elif line[:7] == 'no post':
            opts['dopost'] = False
            line = file.readline()

        elif line[:7] == 'do blas':
            opts['doblas3'] = True
            line = file.readline()
        elif line[:7] == 'no blas':
            opts['doblas3'] = False
            line = file.readline()
        else:
            # Comment this out when debugged:
            print "Unknown line from command section"
            print line,
            print "Assuming end of Input Options Section"
            break
    # end of run options

    # Beginning of setup info
    if line[:6] == 'input ':
        line = file.readline()  # skip line
    # Title
    if line[:5] == 'title':
        opts['title'] = []
        try:
            ntitl = int(line[5])
        except:
            ntitl = 1
        for i in range(ntitl):
            line = file.readline()
            opts['title'].append(line.strip())
        line = file.readline()

    if line[:5] == 'scale':
        line = file.readline()
        opts['scalep'] = float(line.strip())
        line = file.readline()

    # DFT fcnal
    if line[:6] == 'functi':
        line = file.readline()
        opts['dft_func'] = line.strip()
        line = file.readline()

    # Spin polarization
    if line[:6] == 'spin p':
        line = file.readline()
        opts['spinpol'] = int(line.strip())
        #should put an error condition here if dft requires
        # spin and no spinpol input
        line = file.readline()

    # External electric field
    if line[:6] == 'efield':
        line = file.readline()
        ex, ey, ez = map(float, line.split())
        opts['efield'] = (ex, ey, ez)  # in Ry/au
        line = file.readline()

    # External dielectric constant
    if line[:6] == 'dielec':
        line = file.readline()
        opts['dielec'] = float(line.split())
        line = file.readline()

    # Problem dimension
    if line[:6] == 'dimens' or line[:6] == 'lattic':
        line = file.readline()
        opts['ndim'] = int(line.strip())
        line = file.readline()
    else:
        print line
        raise "Dimension must be specified in Quest input"

    # Coordinates (lattice or cartesian)
    if line[:6] == 'coordi':
        line = file.readline()
        opts['coordi'] = line.strip()
        line = file.readline()

    # Problem scaling
    # RPM: Need to do a better job of this:
    #if line[:6] == 'scalep' or (line[:5] == 'scale' and len(line) == 5):
    if line[:6] == 'scalep' or line[:6] == 'scale\n':
        line = file.readline()
        opts['scalep'] = float(line.strip())
        line = file.readline()

    if line[:6] == 'scaleu':
        line = file.readline()
        opts['scaleu'] = float(line.strip())
        line = file.readline()

    if line[:6] == 'scalex':
        line = file.readline()
        opts['scalex'] = float(line.strip())
        line = file.readline()

    if line[:6] == 'scaley':
        line = file.readline()
        opts['scaley'] = float(line.strip())
        line = file.readline()

    if line[:6] == 'scalez':
        line = file.readline()
        opts['scalez'] = float(line.strip())
        line = file.readline()

    # Strain
    if line[:6] == 'strain':
        line = file.readline()
        xx, xy, xz = map(float, line.split())
        line = file.readline()
        yx, yy, yz = map(float, line.split())
        line = file.readline()
        zx, zy, zz = map(float, line.split())
        opts['strain'] = (xx, xy, xz, yx, yy, yz, zx, zy, zz)
        line = file.readline()
    if line[:6] == 'strfac':
        line = file.readline()
        opts['strfac'] = float(line.strip())
        line = file.readline()

    # Lattice vectors:
    if line[:6] == 'primit':
        line = file.readline()
        ax, ay, az = map(float, line.split())
        axyz = ax * bohr2ang, ay * bohr2ang, az * bohr2ang
        line = file.readline()
        bx, by, bz = map(float, line.split())
        bxyz = bx * bohr2ang, by * bohr2ang, bz * bohr2ang
        line = file.readline()
        cx, cy, cz = map(float, line.split())
        cxyz = cx * bohr2ang, cy * bohr2ang, cz * bohr2ang
        cell = Cell(axyz, bxyz, cxyz)
        line = file.readline()

    # grid dimensions
    if line[:6] == 'grid d' or line[:6] == 'points':
        line = file.readline()
        opts['griddim'] = map(int, line.split())
        line = file.readline()

    # nearby function
    if line[:6] == 'nearby':
        line = file.readline()
        opts['nearby'] = int(line.strip())
        line = file.readline()

    # number of atom types
    if line[:6] == 'atom t':
        line = file.readline()
        opts['ntyp'] = int(line.strip())
        opts['types'] = []
        line = file.readline()
    else:
        print line, len(line)
        raise "Number of atom types must be specified"

    # atom types:
    for i in range(opts['ntyp']):
        if line[:6] == 'atom f':
            line = file.readline()
            opts['types'].append(line.strip())
            line = file.readline()
        else:
            raise "Error: expecting another atom file"

    # number of atoms
    if line[:6] == 'number':
        line = file.readline()
        opts['nat'] = int(line.strip())
        line = file.readline()

    if line[:6] == 'atom, ':
        for i in range(opts['nat']):
            line = file.readline()
            words = line.split()
            inum = int(words[0])
            ityp = int(words[1])
            x, y, z = map(float, words[2:5])
            xyz = x * bohr2ang, y * bohr2ang, z * bohr2ang
            xyz = array(xyz)
            sym = cleansym(opts['types'][ityp - 1])
            atno = sym2no[sym]
            material.add_atom(Atom(atno, xyz))
        line = file.readline()
        material.set_cell(cell)
        material.bonds_from_distance()
    else:
        raise "Error: expected atom listing here"

    # to lattice/to cartesian
    if line[:6] == 'to_lat':
        opts['to_lat'] = True
        line = file.readline()
    elif line[:6] == 'to_car':
        opts['to_car'] = True
        line = file.readline()

    # origin offset
    if line[:6] == 'origin':
        line = file.readline()
        opts['dorig'] = map(float, line.split())
        line = file.readline()

    # wigner-seitz origin
    if line[:6] == 'wigner':
        line = file.readline()
        opts['rchrg'] = map(float, line.split())
        line = file.readline()

    # center of symmetry
    if line[:6] == 'symmet':
        line = file.readline()
        opts['rsym'] = map(float, line.split())
        line = file.readline()

    # bloch info
    if line[:5] == 'kgrid':
        line = file.readline()
        opts['kgrid'] = map(int, line.split())
        line = file.readline()
    elif line[:4] == 'khex':
        line = file.readline()
        opts['khex'] = map(int, line.split())
        line = file.readline()

    # skipping more detailed bloch info for now
    if line[:6] == 'n bloc':
        line = file.readline()
        opts['nk'] = int(line.strip())
        line = file.readline()

    if line[:6] == 'scalin':
        line = file.readline()
        opts['scalin'] = map(float, line.split())
        line = file.readline()

    if line[:6] == 'lattic':
        line = file.readline()
        opts['bloch_lattic'] = map(float, line.split())
        line = file.readline()
    elif line[:6] == 'cartes':
        line = file.readline()
        opts['bloch_cartes'] = map(float, line.split())
        line = file.readline()

    if line[:6] == 'bloch ':
        opts['bloch_vecs'] = []
        for i in range(opts['nk']):
            line = file.readline()
            opts['bloch_vecs'].append(map(float, line.split()))
        line = file.readline()

    # symmetry info
    if line[:6] == 'symops':
        line = file.readline()
        opts['nsymi'] = int(line.strip())
        line = file.readline()

    if line[:6] == 'defini':
        opts['symvecs'] = []
        for i in range(opts['nsymi']):
            line = file.readline()
            words = line.split()
            type = int(words[0])
            s1, s2, s3, s4, s5, s6 = map(float, words[1:])
            opts['symvecs'].append((type, s1, s2, s3, s4, s5, s6))
        line = file.readline()

    if line[:6] == 'end se':
        line = file.readline()
    else:
        raise "Expected end setup phase tag"
    # End of setup info

    # Beginning of Run Data
    if line[:6] == 'run ph':
        while 1:
            line = file.readline()
            if not line: break
            if line[:6] == 'end ru' or line[:6] == 'end of':
                break
            elif line[:6] == 'do fla':
                opts['doflag'] = True
            elif line[:6] == 'no fla':
                opts['doflag'] = False
            elif line[:6] == 'first ':
                line = file.readline()
                opts['itstart'] = int(line.strip())
            elif line[:6] == 'last i':
                line = file.readline()
                opts['itstop'] = int(line.strip())
            elif line[:6] == 'histor':
                line = file.readline()
                opts['nhiste'] = int(line.strip())
            elif line[:6] == 'restar':
                line = file.readline()
                opts['itrst'] = int(line.strip())
            elif line[:6] == 'states':
                line = file.readline()
                opts['nstate'] = int(line.strip())
            elif line[:6] == 'temper':
                line = file.readline()
                opts['etemp'] = float(line.strip())
            elif line[:6] == 'blend ' or line[:6] == 'percen':
                line = file.readline()
                opts['scfblnd'] = float(line.strip())
            elif line[:6] == 'scfbl2':
                line = file.readline()
                opts['scfbl2'] = float(line.strip())
            elif line[:6] == 'conver':
                line = file.readline()
                opts['scfconv'] = float(line.strip())
            elif line[:6] == 'alfast':
                line = file.readline()
                opts['alfast'] = float(line.strip())
            elif line[:6] == 'cutii ':
                line = file.readline()
                opts['convii'] = float(line.strip())
            elif line[:6] == 'cutslo':
                line = file.readline()
                opts['convsl'] = float(line.strip())
            elif line[:6] == 'cut2s ':
                line = file.readline()
                opts['conv2s'] = float(line.strip())
            elif line[:6] == 'cutset':
                line = file.readline()
                opts['cutset'] = float(line.strip())
            elif line[:6] == 'cutfrc':
                line = file.readline()
                opts['cutfrc'] = float(line.strip())
            elif line[:6] == 'cutgrd':
                line = file.readline()
                opts['convgr'] = float(line.strip())
            elif line[:6] == 'cut1c ':
                line = file.readline()
                opts['conv1c'] = float(line.strip())
            elif line[:6] == 'geomet':
                # Jump into Geometry Data
                opts['write_geo_sect'] = True
                while 1:
                    line = file.readline()
                    if line[:4] == 'stop' or line[:3] == 'end':
                        break
                    elif line[:6] == 'relax ':
                        opts['dorelax'] = True
                        opts['geo_dorelax'] = True
                    elif line[:6] == 'grelax':
                        line = file.readline()
                        opts['relax_range'] = map(int, line.split())
                    elif line[:6] == 'gfixed':
                        line = file.readline()
                        opts['fixed_range'] = map(int, line.split())
                    elif line[:6] == 'only r':
                        line = file.readline()
                        opts['only_relax'] = int(line.strip())
                    elif line[:6] == 'frame ':
                        line = file.readline()
                        opts['relax_frame'] = map(int, line.split())
                    elif line[:6] == 'defect':
                        line = file.readline()
                        opts['defect'] = int(line.strip())
                    elif line[:6] == 'gblend':
                        line = file.readline()
                        opts['gblend'] = float(line.strip())
                    elif line[:5] == 'gconv':
                        line = file.readline()
                        opts['gconv'] = float(line.strip())
                    elif line[:6] == 'gstart':
                        line = file.readline()
                        opts['gstart'] = int(line.strip())
                    elif line[:6] == 'gsteps':
                        line = file.readline()
                        opts['gsteps'] = int(line.strip())
                    elif line[:6] == 'ghisto':
                        line = file.readline()
                        opts['nhistg'] = int(line.strip())
                    elif line[:6] == 'no ges':
                        opts['igges'] = 0
                    elif line[:6] == 'guess ':
                        line = file.readline()
                        opts['igges'] = int(line.strip())
                    elif line[:6] == 'gmetho':
                        line = file.readline()
                        opts['gmethod'] = line.strip()
                    elif line[:6] == 'timest':
                        line = file.readline()
                        opts['gtstep'] = float(line.strip())
                    else:
                        print "Unknown geomdata line:"
                        print line
                # End of Geometry Data
            elif line[:5] == 'cell ':
                # Jump into Cell Data
                opts['write_cell_sect'] = True
                while 1:
                    line = file.readline()
                    if line[:6] == 'end ce':
                        break
                    elif line[:6] == 'ucstep':
                        line = file.readline()
                        opts['maxucsteps'] = int(line.strip())
                    elif line[:6] == 'ucconv':
                        line = file.readline()
                        opts['ucconv'] = float(line.strip())
                    elif line[:6] == 'pressu':
                        line = file.readline()
                        opts['pressure'] = float(line.strip())
                    elif line[:6] == 'uniaxi':
                        line = file.readline()
                        opts['uniaxial'] = map(float, line.split())
                    elif line[:6] == 'stress':
                        opts['stress'] = []
                        for i in range(opts['ndim']):
                            line = file.readline()
                            opts['stress'].append(map(float, line.split()))
                    elif line[:6] == 'uchist':
                        line = file.readline()
                        opts['nhistuc'] = int(line.strip())
                    elif line[:6] == 'ucmeth':
                        line = file.readline()
                        opts['ucmeth'] = line.strip()
                    elif line[:6] == 'str_br':
                        line = file.readline()
                        opts['strsbroy'] = float(line.strip())
                    elif line[:6] == 'max_st':
                        line = file.readline()
                        opts['strnmax'] = float(line.strip())
                    elif line[:6] == 'cell_f':
                        line = file.readline()
                        opts['cell_f'] = float(line.strip())
                    elif line[:6] == 'bulk_m':
                        line = file.readline()
                        opts['bmod'] = float(line.strip())
                    elif line[:6] == 'uc_ble':
                        line = file.readline()
                        opts['ucblend'] = float(line.strip())
                    else:
                        print "Unknown celldata line:"
                        print line
                # End of Cell Data
            else:
                print "Unknown rundata line:"
                print line
    # End of Run Data

    # Start of MD Data
    line = file.readline()
    if line[:6] == 'md dat':
        while 1:
            line = file.readline()
            if line[:3] == 'end':
                break
            elif line[:6] == 'temper':
                line = file.readline()
                opts['mdtemp'] = float(line.strip())
            elif line[:6] == 'time s':
                line = file.readline()
                opts['ntstep'] = int(line.strip())
            elif line[:6] == 'equil ':
                line = file.readline()
                opts['neqsteps'] = int(line.strip())
            elif line[:6] == 'step s':
                line = file.readline()
                opts['md_dt'] = float(line.strip())
            elif line[:6] == 'md typ':
                line = file.readline()
                opts['mdtype'] = line.strip()
            else:
                print "Unknown md flag"
                print line
    return material
Exemplo n.º 21
0
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