Esempio n. 1
0
def main(mmpInputFile, xyzInputFile=None, outf=None,
         referenceInputFile=None, generateFlag=False):
    bondLengthTerms = { }
    bondAngleTerms = { }

    def addBondLength(atm1, atm2):
        assert atm1 != atm2
        if atm2 < atm1:
            atm1, atm2 = atm2, atm1
        if bondLengthTerms.has_key(atm1):
            if atm2 not in bondLengthTerms[atm1]:
                bondLengthTerms[atm1].append(atm2)
        else:
            bondLengthTerms[atm1] = [ atm2 ]

    def getBonds(atm1):
        lst = [ ]
        if bondLengthTerms.has_key(atm1):
            for x in bondLengthTerms[atm1]:
                lst.append(x)
        for key in bondLengthTerms.keys():
            if atm1 in bondLengthTerms[key]:
                if key not in lst:
                    lst.append(key)
        lst.sort()
        return lst

    def addBondAngle(atm1, atm2, atm3):
        if atm3 < atm1:
            atm1, atm3 = atm3, atm1
        value = (atm2, atm3)
        if bondAngleTerms.has_key(atm1):
            if value not in bondAngleTerms[atm1]:
                bondAngleTerms[atm1].append(value)
        else:
            bondAngleTerms[atm1] = [ value ]

    if outf != None:
        ss, sys.stdout = sys.stdout, outf
    mmp = MmpFile()
    mmp.read(mmpInputFile)
    xyz = XyzFile()
    if xyzInputFile != None:
        xyz.read(xyzInputFile)
    else:
        # copy xyz file from mmp file
        import Atom
        for i in range(len(mmp)):
            ma = mmp.atoms[i]
            element = Atom._PeriodicTable[ma.elem]
            x, y, z = ma.x, ma.y, ma.z
            a = Atom.Atom()
            a.fromXyz(element, x, y, z)
            xyz.atoms.append(a)

    assert len(xyz) != 0
    assert len(xyz) == len(mmp)

    # store all the bonds in bondLengthTerms
    for i in range(len(mmp)):
        a = mmp.atoms[i]
        for b in a.bonds:
            addBondLength(i, b - 1)

    # generate angles from chains of two bonds
    for first in range(len(mmp)):
        for second in getBonds(first):
            for third in getBonds(second):
                if first != third:
                    addBondAngle(first, second, third)

    lengthList = [ ]
    for first in bondLengthTerms.keys():
        for second in bondLengthTerms[first]:
            lengthList.append((first, second,
                               measureLength(xyz, first, second)))
    angleList = [ ]
    for first in bondAngleTerms.keys():
        for second, third in bondAngleTerms[first]:
            angleList.append((first, second, third,
                              measureAngle(xyz, first, second, third)))

    if generateFlag:
        for a1, a2, L in lengthList:
            print "LENGTH", a1, a2, L
        for a1, a2, a3, A in angleList:
            print "ANGLE", a1, a2, a3, A

    if referenceInputFile != None:
        badness = False
        # read in LENGTH lines, compare them to this guy
        inf = open(referenceInputFile)
        lp = ap = 0
        for line in inf.readlines():
            if line.startswith("LENGTH "):
                fields = line[7:].split()
                a1, a2, L = (string.atoi(fields[0]),
                             string.atoi(fields[1]),
                             string.atof(fields[2]))
                a11, a22, LL = lengthList[lp]
                lp += 1
                if a1 != a11 or a2 != a22:
                    print ("Wrong length term (%d, %d), should be (%d, %d)"
                           % (a11, a22, a1, a2))
                    badness = True
                    break
                if abs(L - LL) > LENGTH_TOLERANCE:
                    print ("Wrong bond length at (%d, %d), it's %f, should be %f"
                           % (a1, a2, LL, L))
                    badness = True
                    break
            elif line.startswith("ANGLE "):
                fields = line[6:].split()
                a1, a2, a3, A = (string.atoi(fields[0]),
                                 string.atoi(fields[1]),
                                 string.atoi(fields[2]),
                                 string.atof(fields[3]))
                a11, a22, a33, AA = angleList[ap]
                ap += 1
                if a1 != a11 or a2 != a22 or a3 != a33:
                    print ("Wrong angle term (%d, %d, %d), should be (%d, %d, %d)"
                           % (a11, a22, a33, a1, a2, a3))
                    badness = True
                    break
                if abs(L - LL) > ANGLE_TOLERANCE:
                    print ("Wrong bond angle at (%d, %d, %d), it's %f, should be %f"
                           % (a1, a2, a3, AA, A))
                    badness = True
                    break
            else:
                print "Unknown line in reference file:", line
                badness = True
                break
        if not badness:
            print "OK"
    if outf != None:
        outf.close()
        sys.stdout = ss
Esempio n. 2
0
    mmp2xyz.py input.mmp > output.xyz

$Id$
"""

__author__ = "Will"

import sys
from MmpFile import MmpFile
from XyzFile import XyzFile
import Atom

try:
    mmpInputFile = sys.argv[1]

    xyz = XyzFile()
    mmp = MmpFile()
    mmp.read(mmpInputFile)

    for i in range(len(mmp)):
        ma = mmp.atoms[i]
        element = Atom._PeriodicTable[ma.elem]
        x, y, z = ma.x, ma.y, ma.z
        a = Atom.Atom()
        a.fromXyz(element, x, y, z)
        xyz.atoms.append(a)

    xyz.write(mmpInputFile)

except Exception, e:
    if e:
Esempio n. 3
0
    xyzmerge.py input1.mmp input2.xyz > output.mmp

$Id: xyzmerge.py 8124 2005-11-21 16:43:17Z wware $
"""

__author__ = "Will"

import sys
from MmpFile import MmpFile
from XyzFile import XyzFile

try:
    mmpInputFile = sys.argv[1]
    xyzInputFile = sys.argv[2]

    xyz = XyzFile()
    xyz.read(xyzInputFile)
    mmp = MmpFile()
    mmp.read(mmpInputFile)

    assert len(xyz) != 0
    assert len(xyz) == len(mmp)

    for i in range(len(xyz)):
        xa = xyz.atoms[i]
        ma = mmp.atoms[i]
        assert xa.elem == ma.elem
        ma.x, ma.y, ma.z = xa.x, xa.y, xa.z

    mmp.write()
Esempio n. 4
0
    xyzmerge.py input1.mmp input2.xyz > output.mmp

$Id$
"""

__author__ = "Will"

import sys
from MmpFile import MmpFile
from XyzFile import XyzFile

try:
    mmpInputFile = sys.argv[1]
    xyzInputFile = sys.argv[2]

    xyz = XyzFile()
    xyz.read(xyzInputFile)
    mmp = MmpFile()
    mmp.read(mmpInputFile)

    assert len(xyz) != 0
    assert len(xyz) == len(mmp)

    for i in range(len(xyz)):
        xa = xyz.atoms[i]
        ma = mmp.atoms[i]
        assert xa.elem == ma.elem
        ma.x, ma.y, ma.z = xa.x, xa.y, xa.z

    mmp.write()