Beispiel #1
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
Beispiel #2
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
Beispiel #3
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