コード例 #1
0
ファイル: dmddat2mtxyz.py プロジェクト: lidaobing/itcc
    def test_1(self):
        import base64
        import StringIO
        from itcc.tools import dmddat2mtxyz
        from itcc.core.frame import parseframe

        dmddatfile = StringIO.StringIO(base64.decodestring(test_in_dmddat_base64))
        molfile = StringIO.StringIO(test_in_mol)
        ofile = StringIO.StringIO()
        frame = parseframe("1-3/2,4-8/3")
        dmddat2mtxyz.dmddat2mtxyz(dmddatfile, molfile, ofile, frame)
        self.assertEqual(ofile.getvalue(), test_out)
コード例 #2
0
ファイル: dmddat2mtxyz.py プロジェクト: lidaobing/itcc
def main():
    import sys
    from optparse import OptionParser

    usage = "usage: %prog [-h|options] dmddatfname molfname"
    parser = OptionParser(usage)
    parser.add_option(
    	"-f", "--frame", dest='frame_str',
	default=None,
	help="select frame, " \
             "format is 'begin[-end[/step]](,begin[-end[/step]])*', " \
             "for example '-f 2-40/3,71-91/2'")
    (options, args) = parser.parse_args()

    frame = parseframe(options.frame_str)

    if len(args) != 2:
        parser.error("incorrect number of arguments")

    dmddat2mtxyz(file(args[0]), file(args[1]), sys.stdout, frame)
コード例 #3
0
ファイル: frame.py プロジェクト: lidaobing/itcc
 def test_1(self):
     self.assertEqual(tuple(frame.parseframe('1,2')), (0,1))
     self.assertEqual(tuple(frame.parseframe('1-3')), (0,1,2))
     self.assertEqual(tuple(frame.parseframe('1-3/2')), (0,2))
     self.assertEqual(tuple(frame.parseframe('3/2')), (2,))
     self.assertEqual(tuple(frame.parseframe(None)), ())
コード例 #4
0
ファイル: rmsd.py プロジェクト: lidaobing/itcc
def main_common(rmsd_func):
    from optparse import OptionParser
    usage = "\n" \
            "    %prog [options] xyzfname1 xyzfname2\n" \
            "    %prog [options] -F FILE\n" \
            "    %prog -h"
    parser = OptionParser(usage=usage)
    parser.set_default("no_h", False)
    parser.add_option('-H', "--no-h", dest="no_h",
                      action="store_true",
                      help="does not include hydrogen")
    parser.add_option('-a', "--atoms", dest="atoms",
                      help="only compare selected atoms, 1-based",
                      metavar="STRING")
    parser.add_option('-A', "--atomsfile", dest="atomsfile",
                      help="read the selected atoms from file",
                      metavar="FILE")
    parser.add_option('-b', "--atoms1", dest="atoms1",
                      help="the selected atoms for molecule 1",
                      metavar="STRING")
    parser.add_option('-B', "--atoms1file", dest="atoms1file",
                      help="read the selected atoms from file",
                      metavar="FILE")
    parser.add_option('-c', "--atoms2", dest="atoms2",
                      help="the selected atoms for molecule 2",
                      metavar="STRING")
    parser.add_option('-C', "--atoms2file", dest="atoms2file",
                      help="read the selected atoms from file",
                      metavar="FILE")
    parser.add_option('-F', "--files", dest="files",
                      help="read the compare file lists from FILE",
                      metavar="FILE")
    parser.add_option('-s', '--loop-step', 
                      dest='loop_step',
                      type='int',
                      help='logical symmetry: loop step')
    parser.add_option('-m', '--mirror',
                      dest='mirror',
                      action='store_true',
                      help='also consider the mirror molecule')
    parser.add_option('-v', '--verbose',
                      dest='verbose',
                      action='store_true',
                      help='be verbose')
    (options, args) = parser.parse_args()

    if len(args) == 2 and options.files is None:
        pass
    elif len(args) == 0 and options.files:
        pass
    else:
        parser.error("incorrect number of arguments")

    if (options.atoms and options.atomsfile) or \
       (options.atoms1 and options.atoms1file) or \
       (options.atoms2 and options.atoms2file):
        parser.error("options conflict")

    atoms1 = None
    atoms2 = None
    if options.atomsfile:
        options.atoms = file(options.atomsfile).read()
    if options.atoms:
        atoms1 = list(frame.parseframe(options.atoms))
        atoms2 = atoms1[:]
    if options.atoms1file:
        options.atoms1 = file(options.atoms1file).read()
    if options.atoms1:
        atoms1 = frame.parseframe(options.atoms1)

    if options.atoms2file:
        options.atoms2 = file(options.atoms2file).read()
    if options.atoms2:
        atoms2 = frame.parseframe(options.atoms2)

    filelists = []
    if options.files is not None:
        filelists = [line.split() for line in file(options.files).readlines()]
    else:
        filelists = [args]

    from itcc.molecule import read

    mol_cache = {}
    for filepair in filelists:
        fname1 = filepair[0]
        fname2 = filepair[1]
        if options.verbose:
            print fname1, fname2,
        mol1 = cache_mol(fname1, mol_cache)
        mol2 = cache_mol(fname2, mol_cache)

        if options.no_h:
            if atoms1 is None:
                atoms1 = range(len(mol1))
            atoms1 = [x for x in atoms1 if mol1.atoms[x].no != 1]

        if options.no_h:
            if atoms2 is None:
                atoms2_new = range(len(mol2))
            else:
                atoms2_new = atoms2
            atoms2_new = [x for x in atoms2_new if mol2.atoms[x].no != 1]
        else:
            atoms2_new = atoms2
        print rmsd_func(mol1, mol2, atoms1, atoms2_new, 
                        options.mirror, options.loop_step)