Example #1
0
 def write_data(self,file):
     from Util import cleansym
     from Element import sym2no
     file.write(' $DATA\n')
     file.write('%s GAMESS job generated automatically by gamess.py\n'
                % self.name)
     file.write('C1\n')
     for atom in self.atomlist:
         name,x,y,z = atom
         sym = cleansym(name)
         atno = sym2no[sym]
         file.write('%s %5.1f %12.6f %12.6f %12.6f\n' %\
                    (name,atno,x,y,z))
     file.write(' $END\n')
     return
Example #2
0
def read_xyz(xyz_name):
    'Takes the last structure from an xyz file'
    xyz_file = open(xyz_name,'r')
    while 1:
        line = xyz_file.readline()
        if not line: break
        words = string.split(line)
        if not words: break
        nat = int(words[0])
        title = xyz_file.readline()
        atoms = []
        for i in range(nat):
            line = xyz_file.readline()
            words = string.split(line)
            sym = words[0]
            sym = cleansym(sym)
            x,y,z = float(words[1]),float(words[2]),float(words[3])
            atoms.append((sym,x,y,z))

    xyz_file.close()
    return atoms
Example #3
0
def read(filename,do_center=0):
    "Read all the frames from an XYZ file. Optionally center each frame"
    file = open(filename)
    geometries = []
    while 1:
        line = file.readline()
        if not line: break
        try:
            nat = int(line.split()[0])
        except:
            break
        title = file.readline()
        atoms = []
        for i in range(nat):
            line = file.readline()
            words = line.split()
            atno = sym2no[cleansym(words[0])]
            x,y,z = map(float,words[1:4])
            atoms.append((atno,(x,y,z)))
        if do_center: atoms = center(atoms)
        geometries.append(atoms)
    return geometries