示例#1
0
def coordinates_read(fname=None):
    """
    1 COP   C1         1    2.122800112    1.917699933    2.044047117
||||| ----- |||||       |||||||||||||||---------------|||||||||||||||
.123456789.123456789.123456789.123456789.123456789.123456789.123456789
    """
    mol = qm3.mol.molecule()
    f = qm3.fio.open_r(fname)
    l = f.readline()
    while (l.strip() != "POSITION"):
        l = f.readline()
    l = f.readline()
    while (l.strip() != "END"):
        mol.natm += 1
        mol.segn.append("A")
        mol.resi.append(int(l[0:5]))
        mol.resn.append(l[6:11].strip())
        mol.labl.append(l[12:17].strip())
        mol.coor.append(float(l[24:39].strip()) * 10.0)
        mol.coor.append(float(l[39:54].strip()) * 10.0)
        mol.coor.append(float(l[54:69].strip()) * 10.0)
        l = f.readline()
    l = f.readline()
    if (l.strip() == "BOX"):
        mol.boxl = [float(i) * 10.0 for i in f.readline().strip().split()]
    qm3.fio.close(f, fname)
    mol.settle()
    return (mol)
示例#2
0
文件: xplor.py 项目: zhenglz/qm3
def psf_read(mol, fname):
    global __topo
    mol.type = []
    mol.chrg = []
    mol.mass = []
    f = qm3.fio.open_r(fname)
    if (f.readline().split()[0] == "PSF"):
        f.readline()
        for i in range(int(f.readline().split()[0]) + 1):
            f.readline()
        n = int(f.readline().split()[0])
        if (mol.natm == 0):
            mol.natm = n
            mol.segn = []
            mol.resi = []
            mol.resn = []
            mol.labl = []
            for i in range(n):
                t = f.readline().split()
                mol.segn.append(t[1])
                mol.resi.append(int(t[2]))
                mol.resn.append(t[3])
                mol.labl.append(t[4])
                mol.type.append(t[5])
                mol.chrg.append(float(t[6]))
                mol.mass.append(float(t[7]))
            mol.settle()
        elif (mol.natm == n):
            for i in range(mol.natm):
                t = f.readline().split()
                if (mol.segn[i] == t[1] and mol.resi[i] == int(t[2])
                        and mol.resn[i] == t[3] and mol.labl[i] == t[4]):
                    mol.type.append(t[5])
                    mol.chrg.append(float(t[6]))
                    mol.mass.append(float(t[7]))
                else:
                    print("- Wrong PSF data (%d): %s/%s %d/%s %s/%s %s/%s" %
                          (i + 1, mol.segn[i], t[1], mol.resi[i], t[2],
                           mol.resn[i], t[3], mol.labl[i], t[4]))
                    mol.type = []
                    mol.chrg = []
                    mol.mass = []
                    return ([])
        else:
            print("- Invalid number of atoms in PSF!")
            return ([])
    bonds = []
    __topo = f.readline()
    l = f.readline()
    n = int(l.strip().split()[0])
    __topo += l
    while (len(bonds) < n):
        l = f.readline()
        t = [int(i) - 1 for i in l.strip().split()]
        for i in range(len(t) // 2):
            bonds.append([t[2 * i], t[2 * i + 1]])
        __topo += l
    __topo += f.read()
    qm3.fio.close(f, fname)
    return (bonds)
示例#3
0
文件: mol2.py 项目: zhenglz/qm3
def mol2_read(fname=None):
    mol = qm3.mol.molecule()
    f = qm3.fio.open_r(fname)
    l = f.readline()
    while (l != ""):
        if (l.strip() == "@<TRIPOS>MOLECULE"):
            f.readline()
            t = f.readline().strip().split()
            mol.natm = int(t[0])
            nbnd = int(t[1])
            bond = []
        if (l.strip() == "@<TRIPOS>ATOM"):
            for i in range(mol.natm):
                t = f.readline().strip().split()
                mol.labl.append(t[1])
                mol.coor += [float(t[2]), float(t[3]), float(t[4])]
                mol.type.append(t[5])
                mol.resi.append(int(t[6]))
                mol.resn.append(t[7][0:3])
                mol.chrg.append(float(t[8]))
                mol.segn.append("X")
        if (l.strip() == "@<TRIPOS>BOND"):
            for i in range(nbnd):
                t = f.readline().split()
                ii = int(t[1]) - 1
                jj = int(t[2]) - 1
                bond.append([ii, jj])
        l = f.readline()
    qm3.fio.close(f, fname)
    mol.settle()
    return (mol, bond)
示例#4
0
文件: sdf.py 项目: zhenglz/qm3
def sdf_read(fname=None):
    mol = qm3.mol.molecule()
    f = qm3.fio.open_r(fname)
    for i in range(4):
        l = f.readline()
    mol.natm = int(l.strip().split()[0])
    for i in range(mol.natm):
        t = f.readline().split()
        mol.labl.append(t[3])
        mol.resi.append(1)
        mol.resn.append("XXX")
        mol.segn.append("X")
        mol.coor += [float(j) for j in t[0:3]]
    qm3.fio.close(f, fname)
    mol.settle()
    return (mol)
示例#5
0
文件: _lammps.py 项目: zhenglz/qm3
def lammps_read( fname = None ):
    mol = qm3.mol.molecule()
    f = qm3.fio.open_r( fname )
    l = f.readline().lower()
    q = True
    m = {}
    while( l != "" and q ):
        if( l.find( "xlo" ) > 0 and l.find( "xhi" ) > 0 ):
            t = l.strip().split()
            mol.boxl[0] = float( t[1] ) - float( t[0] )
        elif( l.find( "ylo" ) > 0 and l.find( "yhi" ) > 0 ):
            t = l.strip().split()
            mol.boxl[1] = float( t[1] ) - float( t[0] )
        elif( l.find( "zlo" ) > 0 and l.find( "zhi" ) > 0 ):
            t = l.strip().split()
            mol.boxl[2] = float( t[1] ) - float( t[0] )
        elif( l.find( "masses" ) >= 0 ):
            f.readline()
            l = f.readline().strip()
            while( l != "" ):
                t = l.split()
                m[t[0]] = float( t[1] )
                l = f.readline().strip()
        elif( l.find( "atoms" ) == 0 ):
            q = False
            f.readline()
            l = f.readline().strip()
            while( l != "" ):
                t = l.split()
                mol.segn.append( "XXX" )
                mol.resn.append( "X" )
                mol.resi.append( int( t[1] ) )
                mol.labl.append( t[2] )
                mol.mass.append( m[t[2]] )
                mol.chrg.append( float( t[3] ) )
                mol.coor += [ float( t[4] ), float( t[5] ), float( t[6] ) ]
                mol.natm += 1
                l = f.readline().strip()
        l = f.readline().lower()
    qm3.fio.close( f, fname )
    mol.settle()
    return( mol )