def test1(self):
        current_dir = os.path.dirname(__file__)
        db = Database()
        converter = OptimDBConverter(db, 
                                     mindata=os.path.join(current_dir, "min.data"),
                                     tsdata=os.path.join(current_dir, "ts.data"),
                                     pointsmin=os.path.join(current_dir, "points.min"),
                                     pointsts=os.path.join(current_dir, "points.ts"),
                                     endianness="<")
        converter.convert()
        self.assertEqual(db.number_of_minima(), 2)
        self.assertEqual(db.number_of_transition_states(), 1)
        
        ts = db.transition_states()[0]
        self.assertAlmostEqual(ts.coords[0], 1.548324, 5)
        self.assertAlmostEqual(ts.coords[2], 0.18178001, 5)
        self.assertAlmostEqual(ts.coords[-1], -0.50953229, 5)
        self.assertEqual((180,), ts.coords.shape)

        m = db.minima()[0]
        print(repr(m.coords))
        self.assertAlmostEqual(m.coords[0], 1.53700142, 5)
        self.assertAlmostEqual(m.coords[2], 0.87783657, 5)
        self.assertAlmostEqual(m.coords[-1], -0.50953229, 5)
        self.assertEqual((180,), m.coords.shape)
def main():
    parser = argparse.ArgumentParser(description="""
convert an OPTIM database to a pele sqlite database.  Four files are needed.  Normally they are called:

    points.min : the coordinates of the minima in binary format
    min.data   : additional information about the minima (like the energy)
    points.ts  : the coordinates of the transition states
    min.ts     : additional information about transition states (like which minima they connect)

Other file names can optionally be passed.  Some fortran compilers use non-standard endianness to save the
binary data.  If your coordinates are garbage, try changing the endianness.
    """, formatter_class=argparse.RawDescriptionHelpFormatter)
    
    parser.add_argument('--ndof', help='Number of total degrees of freedom (e.g. 3*number of atoms).  This is simply the length of a coordinates vector.', 
                        type=int, default=None)
    parser.add_argument('--Database','-d', help = 'Name of database to write into', type = str, default="optimdb.sqlite")
    parser.add_argument('--Mindata','-m', help = 'Name of min.data file', type = str, default="min.data")
    parser.add_argument('--Tsdata','-t', help = 'Name of ts.data file', type = str, default="ts.data")
    parser.add_argument('--Pointsmin','-p', help = 'Name of points.min file', type = str, default="points.min")
    parser.add_argument('--Pointsts','-q', help = 'Name of points.ts file', type = str, default="points.ts")
    parser.add_argument('--endianness', help = 'set the endianness of the binary data.  Can be "<" for little-endian or ">" for big-endian', type = str, default="=")
    args = parser.parse_args()
    
    db = Database(args.Database)
    
    cv = OptimDBConverter(database=db, ndof=args.ndof, mindata=args.Mindata, 
                 tsdata=args.Tsdata, pointsmin=args.Pointsmin, pointsts=args.Pointsts,
                 endianness=args.endianness)

    cv.setAccuracy()
     
    cv.convert()
    cv.db.session.commit()
def main():
    parser = argparse.ArgumentParser(description=desc, 
                                     formatter_class=argparse.RawDescriptionHelpFormatter)
    
#    parser.add_argument('--ndof', help='Number of total degrees of freedom (e.g. 3*number of atoms).  This is simply the length of a coordinates vector.', 
#                        type=int, default=1)
#    parser.add_argument('--Database','-d', help = 'Name of database to write into', type = str, default="optimdb.sqlite")
#    parser.add_argument('--Mindata','-m', help = 'Name of min.data file', type = str, default="min.data")
#    parser.add_argument('--Tsdata','-t', help = 'Name of ts.data file', type = str, default="ts.data")
#    parser.add_argument('--Pointsmin','-p', help = 'Name of points.min file', type = str, default="points.min")
#    parser.add_argument('--Pointsts','-q', help = 'Name of points.ts file', type = str, default="points.ts")
    parser.add_argument('--endianness', help = 'set the endianness of the binary data.  Can be "<" for little-endian or ">" for big-endian', type = str, default="=")
    args = parser.parse_args()
    
    system = AMBERSystem(prmtopFname="coords.prmtop", inpcrdFname="coords.inpcrd")
    db = system.create_database()
    converter = OptimDBConverter(db, mindata="min.data", 
                 tsdata="ts.data", pointsmin="points.min", pointsts="points.ts",
                 endianness=args.endianness)
    converter.convert()
    
#    system.get_ndof = lambda : args.ndof
    run_gui(system, db=db)
    
    print db.number_of_minima()
    def test1(self):
        current_dir = os.path.dirname(__file__)
        db = Database()
        converter = OptimDBConverter(
            db,
            mindata=os.path.join(current_dir, "min.data"),
            tsdata=os.path.join(current_dir, "ts.data"),
            pointsmin=os.path.join(current_dir, "points.min"),
            pointsts=os.path.join(current_dir, "points.ts"),
            endianness="<")
        converter.convert()
        self.assertEqual(db.number_of_minima(), 2)
        self.assertEqual(db.number_of_transition_states(), 1)

        ts = db.transition_states()[0]
        self.assertAlmostEqual(ts.coords[0], 1.548324, 5)
        self.assertAlmostEqual(ts.coords[2], 0.18178001, 5)
        self.assertAlmostEqual(ts.coords[-1], -0.50953229, 5)
        self.assertEqual((180, ), ts.coords.shape)

        m = db.minima()[0]
        print repr(m.coords)
        self.assertAlmostEqual(m.coords[0], 1.53700142, 5)
        self.assertAlmostEqual(m.coords[2], 0.87783657, 5)
        self.assertAlmostEqual(m.coords[-1], -0.50953229, 5)
        self.assertEqual((180, ), m.coords.shape)
Exemple #5
0
def main():
    parser = argparse.ArgumentParser(
        description=desc, formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument(
        '--ndof',
        help=
        'Number of total degrees of freedom (e.g. 3*number of atoms).  This is simply the length of a coordinates vector.',
        type=int,
        default=1)
    #    parser.add_argument('--Database','-d', help = 'Name of database to write into', type = str, default="optimdb.sqlite")
    #    parser.add_argument('--Mindata','-m', help = 'Name of min.data file', type = str, default="min.data")
    #    parser.add_argument('--Tsdata','-t', help = 'Name of ts.data file', type = str, default="ts.data")
    #    parser.add_argument('--Pointsmin','-p', help = 'Name of points.min file', type = str, default="points.min")
    #    parser.add_argument('--Pointsts','-q', help = 'Name of points.ts file', type = str, default="points.ts")
    #    parser.add_argument('--endianness', help = 'set the endianness of the binary data.  Can be "<" for little-endian or ">" for big-endian', type = str, default="=")
    args = parser.parse_args()

    system = BaseSystem()
    db = system.create_database()
    converter = OptimDBConverter(db,
                                 mindata="min.data",
                                 tsdata="ts.data",
                                 pointsmin="points.min",
                                 pointsts="points.ts",
                                 endianness="=",
                                 assert_coords=False)
    converter.convert_no_coords()

    system.get_ndof = lambda: args.ndof
    run_gui(system, db=db)

    print(db.number_of_minima())
Exemple #6
0
 def setUp(self):
     from pele.utils.optim_compatibility import OptimDBConverter
     from pele.storage import Database
     ndof = 10 # wrong, but who cares.
     self.db = Database()
     current_dir = os.path.dirname(__file__)
     converter = OptimDBConverter(self.db, ndof=ndof, mindata=current_dir+"/collagen.min.data", 
                                  tsdata=current_dir+"/collagen.ts.data", assert_coords=False)
     converter.convert_no_coords()
 def test_nocoords(self):
     current_dir = os.path.dirname(__file__)
     db = Database()
     converter = OptimDBConverter(db, 
                                  mindata=os.path.join(current_dir, "min.data"),
                                  tsdata=os.path.join(current_dir, "ts.data"),
                                  pointsmin="poo",
                                  pointsts="poo",
                                  assert_coords=False,
                                  endianness="<")
     converter.convert()
 def test_nocoords(self):
     current_dir = os.path.dirname(__file__)
     db = Database()
     converter = OptimDBConverter(
         db,
         mindata=os.path.join(current_dir, "min.data"),
         tsdata=os.path.join(current_dir, "ts.data"),
         pointsmin="poo",
         pointsts="poo",
         assert_coords=False,
         endianness="<")
     converter.convert()
 def test_nocoords_Fails(self):
     current_dir = os.path.dirname(__file__)
     db = Database()
     converter = OptimDBConverter(db, 
                                  mindata=os.path.join(current_dir, "min.data"),
                                  tsdata=os.path.join(current_dir, "ts.data"),
                                  pointsmin="poo",
                                  pointsts="poo",
                                  assert_coords=True,
                                  endianness="<")
     with self.assertRaises(IOError):
         converter.convert()
 def test_nocoords_Fails(self):
     current_dir = os.path.dirname(__file__)
     db = Database()
     converter = OptimDBConverter(
         db,
         mindata=os.path.join(current_dir, "min.data"),
         tsdata=os.path.join(current_dir, "ts.data"),
         pointsmin="poo",
         pointsts="poo",
         assert_coords=True,
         endianness="<")
     with self.assertRaises(IOError):
         converter.convert()
    def test1(self):
        current_dir = os.path.dirname(__file__)
        db = Database()
        converter = OptimDBConverter(
            db,
            mindata=os.path.join(current_dir, "min.data"),
            tsdata=os.path.join(current_dir, "ts.data"),
            pointsmin=os.path.join(current_dir, "points.min"),
            pointsts=os.path.join(current_dir, "points.ts"),
            endianness="<")

        converter.convert()

        mdata = tempfile.NamedTemporaryFile(delete=True)
        tsdata = tempfile.NamedTemporaryFile(delete=True)
        pm = tempfile.NamedTemporaryFile(delete=True)
        pts = tempfile.NamedTemporaryFile(delete=True)
        print mdata.name, tsdata.name
        writer = WritePathsampleDB(db,
                                   mindata=mdata.name,
                                   tsdata=tsdata.name,
                                   pointsmin=pm.name,
                                   pointsts=pts.name,
                                   endianness="<")

        writer.write_db()

        d1 = np.genfromtxt(os.path.join(current_dir, "min.data"))[:, :3]
        d2 = np.genfromtxt(mdata.name)[:, :3]
        _base_test.assert_arrays_almost_equal(self, d1, d2)

        d1 = np.genfromtxt(os.path.join(current_dir,
                                        "ts.data")).reshape(-1, 8)[:, :5]
        d2 = np.genfromtxt(tsdata.name).reshape(-1, 8)[:, :5]
        print d1, d2
        _base_test.assert_arrays_almost_equal(self, d1, d2)

        self.assertEqual(sha1_of_file(os.path.join(current_dir, "points.min")),
                         sha1_of_file(pm.name))
        self.assertEqual(sha1_of_file(os.path.join(current_dir, "points.ts")),
                         sha1_of_file(pts.name))
 def test1(self):
     current_dir = os.path.dirname(__file__)
     db = Database()
     converter = OptimDBConverter(db, 
                                  mindata=os.path.join(current_dir, "min.data"),
                                  tsdata=os.path.join(current_dir, "ts.data"),
                                  pointsmin=os.path.join(current_dir, "points.min"),
                                  pointsts=os.path.join(current_dir, "points.ts"),
                                  endianness="<")
     
     converter.convert()
     
     mdata = tempfile.NamedTemporaryFile(delete=True)
     tsdata = tempfile.NamedTemporaryFile(delete=True)
     pm = tempfile.NamedTemporaryFile(delete=True)
     pts = tempfile.NamedTemporaryFile(delete=True)
     print(mdata.name, tsdata.name)
     writer = WritePathsampleDB(db,
                                mindata=mdata.name,
                                tsdata=tsdata.name,
                                pointsmin=pm.name,
                                pointsts=pts.name,
                                endianness="<")
     
     writer.write_db()
     
     d1 = np.genfromtxt(os.path.join(current_dir, "min.data"))[:,:3]
     d2 = np.genfromtxt(mdata.name)[:,:3]
     _base_test.assert_arrays_almost_equal(self, d1, d2)
     
     d1 = np.genfromtxt(os.path.join(current_dir, "ts.data")).reshape(-1,8)[:,:5]
     d2 = np.genfromtxt(tsdata.name).reshape(-1,8)[:,:5]
     print(d1, d2)
     _base_test.assert_arrays_almost_equal(self, d1, d2)
     
     self.assertEqual(sha1_of_file(os.path.join(current_dir, "points.min")),
                      sha1_of_file(pm.name))
     self.assertEqual(sha1_of_file(os.path.join(current_dir, "points.ts")),
                      sha1_of_file(pts.name))
    def test2(self):
        from pele.utils.tests.test_disconnectivity_graph import create_random_database

        db = create_random_database(nmin=20, nts=15)

        delete = False
        mdata = tempfile.NamedTemporaryFile(delete=delete, suffix=".min.data")
        tsdata = tempfile.NamedTemporaryFile(delete=delete, suffix=".ts.data")
        pm = tempfile.NamedTemporaryFile(delete=delete)
        pts = tempfile.NamedTemporaryFile(delete=delete)
        print mdata.name, tsdata.name
        writer = WritePathsampleDB(db,
                                   mindata=mdata.name,
                                   tsdata=tsdata.name,
                                   pointsmin=pm.name,
                                   pointsts=pts.name,
                                   endianness="<")

        writer.write_db()

        newdb = Database()
        reader = OptimDBConverter(newdb,
                                  mindata=mdata.name,
                                  tsdata=tsdata.name,
                                  pointsmin=pm.name,
                                  pointsts=pts.name,
                                  endianness="<")
        reader.convert()

        for m1, m2 in izip(db.minima(), newdb.minima()):
            self.assertAlmostEqual(m1.energy, m2.energy)
            _base_test.assert_arrays_almost_equal(self, m1.coords, m2.coords)

        for ts1, ts2 in izip(db.transition_states(),
                             newdb.transition_states()):
            self.assertAlmostEqual(ts1.energy, ts2.energy)
            _base_test.assert_arrays_almost_equal(self, ts1.coords, ts2.coords)
            self.assertAlmostEqual(ts1.minimum1.energy, ts2.minimum1.energy)
            self.assertAlmostEqual(ts1.minimum2.energy, ts2.minimum2.energy)
 def test2(self):
     from pele.utils.tests.test_disconnectivity_graph import create_random_database
     
     db = create_random_database(nmin=20, nts=15)
     
     delete=False
     mdata = tempfile.NamedTemporaryFile(delete=delete, suffix=".min.data")
     tsdata = tempfile.NamedTemporaryFile(delete=delete, suffix=".ts.data")
     pm = tempfile.NamedTemporaryFile(delete=delete)
     pts = tempfile.NamedTemporaryFile(delete=delete)
     print(mdata.name, tsdata.name)
     writer = WritePathsampleDB(db,
                                mindata=mdata.name,
                                tsdata=tsdata.name,
                                pointsmin=pm.name,
                                pointsts=pts.name,
                                endianness="<")
     
     writer.write_db()
     
     newdb = Database()
     reader = OptimDBConverter(newdb,
                               mindata=mdata.name,
                               tsdata=tsdata.name,
                               pointsmin=pm.name,
                               pointsts=pts.name,
                               endianness="<")
     reader.convert()
     
     for m1, m2 in zip(db.minima(), newdb.minima()):
         self.assertAlmostEqual(m1.energy, m2.energy)
         _base_test.assert_arrays_almost_equal(self, m1.coords, m2.coords)
     
     for ts1, ts2 in zip(db.transition_states(), newdb.transition_states()):
         self.assertAlmostEqual(ts1.energy, ts2.energy)
         _base_test.assert_arrays_almost_equal(self, ts1.coords, ts2.coords)
         self.assertAlmostEqual(ts1.minimum1.energy, ts2.minimum1.energy)
         self.assertAlmostEqual(ts1.minimum2.energy, ts2.minimum2.energy)
def main():
    parser = argparse.ArgumentParser(description="""
convert an OPTIM database to a pele sqlite database.  Four files are needed.  Normally they are called:

    points.min : the coordinates of the minima in binary format
    min.data   : additional information about the minima (like the energy)
    points.ts  : the coordinates of the transition states
    min.ts     : additional information about transition states (like which minima they connect)

Other file names can optionally be passed.  Some fortran compilers use non-standard endianness to save the
binary data.  If your coordinates are garbage, try changing the endianness.
    """, formatter_class=argparse.RawDescriptionHelpFormatter)
    
    parser.add_argument('--ndof', help='Number of total degrees of freedom (e.g. 3*number of atoms).  This is simply the length of a coordinates vector.', 
                        type=int, default=None)
    parser.add_argument('--parentDB', help = 'Name of parent pinned database from which the system properties will be copied. Choose a small one!')
    parser.add_argument('--Database','-d', help = 'Name of database to write into', type = str, default="optimdb.sqlite")
    parser.add_argument('--Mindata','-m', help = 'Name of min.data file', type = str, default="min.data")
    parser.add_argument('--Tsdata','-t', help = 'Name of ts.data file', type = str, default="ts.data")
    parser.add_argument('--Pointsmin','-p', help = 'Name of points.min file', type = str, default="points.min")
    parser.add_argument('--Pointsts','-q', help = 'Name of points.ts file', type = str, default="points.ts")
    parser.add_argument('--endianness', help = 'set the endianness of the binary data.  Can be "<" for little-endian or ">" for big-endian', type = str, default="=")
    parser.add_argument('--nopoints', help = 'Load the metadata for minima and transition states without reading the coordinates (usually to save storage space)', action = 'store_true')
    args = parser.parse_args()
    
    system, basedb, x0 = create_frozenblj_system_from_db(args.parentDB)

    db = Database(args.Database)

    props = basedb.properties(as_dict=True)
    for key, prop in props.iteritems():
        db.add_property(key, prop)
    
    cv = OptimDBConverter(database=db, ndof=args.ndof, mindata=args.Mindata, 
                 tsdata=args.Tsdata, pointsmin=args.Pointsmin, pointsts=args.Pointsts,
                 endianness=args.endianness, coords_converter=system.coords_converter.get_reduced_coords)

    cv.setAccuracy()
     
    if args.nopoints:
        cv.convert_no_coords()
    else:
        cv.convert()
    cv.db.session.commit()
Exemple #16
0
def main():
    if len(sys.argv) < 2:
        usage()
        exit(1)
    
    
    
    kwargs = {}
    outfile = None
    OPTIM = False

    opts, args = getopt.gnu_getopt(sys.argv[1:], "ho:", 
                                   ["help", "nlevels=", "subgraph_size=", "OPTIM",
                                    "order_by_basin_size", "order_by_energy",
                                    "include_gmin",
                                    "center_gmin",
                                    "Emax=",
                                    ])
    for o, a in opts:
        if o == "-h" or o == "--help":
            usage()
            exit(1)
        if o == "-o":
            outfile = a 
        elif o == "--nlevels":
            kwargs["nlevels"] = int(a)
        elif o == "--Emax":
            kwargs["Emax"] = float(a)
        elif o == "--subgraph_size":
            kwargs["subgraph_size"] = int(a)
        elif o == "--order_by_basin_size":
            kwargs["order_by_basin_size"] = True
        elif o == "--order_by_energy":
            kwargs["order_by_energy"] = True
        elif o == "--includer_gmin":
            kwargs["includer_gmin"] = True
        elif o == "--center_gmin":
            kwargs["center_gmin"] = True
        elif o == "--OPTIM":
            OPTIM = True
        else:
            print "don't understand", o, a
            print ""
            usage()
            exit(1)
    
    
    groups = None
    
    if OPTIM:
        #make database from min.data ts.data
        db = Database()
        converter = OptimDBConverter(db)
        converter.convert_no_coords()
        groups = read_AB(db)
    else:
        if len(args) == 0:
            print "you must specify database file"
            print ""
            usage()
            exit()
        dbfile = args[0]
        if not os.path.exists(dbfile):
            print "database file doesn't exist", dbfile
            exit()
        
        db = Database(dbfile)
        
    if outfile is None and use_gui:
        app = QApplication(sys.argv) 
        kwargs["show_minima"] = False
        md = DGraphDialog(db, params=kwargs)
        md.rebuild_disconnectivity_graph()
        if groups is not None:
            md.dgraph_widget.dg.color_by_group(groups)
            md.dgraph_widget.redraw_disconnectivity_graph()
        md.show()
        sys.exit(app.exec_())
        
    # make graph from database
    t0 = time.time()
    if "Emax" in kwargs and use_gui:
        graph = reduced_db2graph(db, kwargs['Emax'])
    else:
        graph = dg.database2graph(db)
    t1 = time.time()
    print "loading the data into a transition state graph took", t1-t0, "seconds"

    # do the disconnectivity graph analysis
    mydg = dg.DisconnectivityGraph(graph, **kwargs)
    print "doing disconnectivity graph analysis"
    sys.stdout.flush()
    t1 = time.time()
    mydg.calculate()
    t2 = time.time()
    print "d-graph analysis finished in", t2-t1, "seconds"
    print "number of minima:", mydg.tree_graph.number_of_leaves()
    print "plotting disconnectivigy graph"
    sys.stdout.flush()
    
    
    # make the figure and save it
    mydg.plot()
    if outfile is None:
        plt.show()
    else:
        plt.savefig(outfile)
    t3 = time.time()
    print "plotting finished in", t3-t2, "seconds"
Exemple #17
0
            if i == 0:
                nminima = int(line.split()[0])
            else:
                sline = line.split()
                ids += map(int, sline)
    
    assert nminima == len(ids)
    print len(ids), "minima read from file:", fname
    return [db.getMinimum(mid) for mid in ids]


db = Database()
direc = "lj38/20000.minima"
direc = "."
if db.number_of_minima() == 0:
    converter = OptimDBConverter(db, mindata=direc+"/min.data", 
             tsdata=direc+"/ts.data")
    converter.pointsmin_data = None
    converter.pointsts_data = None
    converter.ReadMinDataFast()
    converter.ReadTSdataFast()




A = read_minA(direc+"/min.A", db)
B = read_minA(direc+"/min.B", db)
print len(A), "A minima"
print len(B), "B minima"

        
        
Exemple #18
0
                        help="output file name. The heat capacity will be written to output and output.pdf", default="Cv")   
    parser.add_argument("--Tmin", type=float, help="Minimum temperature for the calculation.", default=0.02)
    parser.add_argument("--Tmax", type=float, help="Minimum temperature for the calculation.", default=1.0)
    parser.add_argument("--Tcount", type=int, help="Number of temperature points for the calculation.", default=300)
    parser.add_argument("--OPTIM", action="store_true", help="read data from a min.data file instead."
                        "fname should be the filename of the min.data file")
    args = parser.parse_args()
    print args.fname
    print args
    k = args.k
    
    # get the list of minima
    if args.OPTIM:
        # fname is a min.data file
        db = Database()
        converter = OptimDBConverter(db, mindata=args.fname)
        converter.convert_no_coords()
        minima = db.minima()
    else:
        dbfname = args.fname
        db = Database(dbfname, createdb=False)
        minima = [m for m in db.minima() if m.fvib is not None and m.pgorder is not None]
        if len(minima) == 0:
            print "There are not minima with the necessary thermodynamic information in the database.  Have you computed the normal mode"\
                  " frequencies and point group order for all the minima?  See pele.thermodynamics "\
                  " for more information"
            exit(1)
    print "computing heat capacity from", len(minima), "minima"

    Tmin = args.Tmin
    Tmax = args.Tmax
def main():
    if len(sys.argv) < 2:
        usage()
        exit(1)
    
    
    # The default is to use the largest connected component of the graph, 
    # rather than the component which includes the global minimum.
    kwargs = {"include_gmin":False, "center_gmin":False}
    outfile, colourfile, groupcolourfile, idfile = None, None, None, None
    aspect = 6.0/7.0
    width = 6
    OPTIM = False

    opts, args = getopt.gnu_getopt(sys.argv[1:], "ho:", 
                                   ["help", "nlevels=", "subgraph_size=", "OPTIM",
                                    "order_by_basin_size", "order_by_energy",
                                    "include_gmin",
                                    "center_gmin",
                                    "Emax=",
                                    "colourfile=",
                                    "groupcolourfile=",
                                    "idfile=",
                                    "shape=",
                                    "width="
                                    ])
    for o, a in opts:
        if o == "-h" or o == "--help":
            usage()
            exit(1)
        if o == "-o":
            outfile = a 
        elif o == "--nlevels":
            kwargs["nlevels"] = int(a)
        elif o == "--Emax":
            kwargs["Emax"] = float(a)
        elif o == "--subgraph_size":
            kwargs["subgraph_size"] = int(a)
        elif o == "--order_by_basin_size":
            kwargs["order_by_basin_size"] = True
        elif o == "--order_by_energy":
            kwargs["order_by_energy"] = True
        elif o == "--include_gmin":
            kwargs["include_gmin"] = True
        elif o == "--center_gmin":
            kwargs["center_gmin"] = True
        elif o == "--OPTIM":
            OPTIM = True
        elif o == "--colourfile":
            colourfile = a
            print "Setting colourfile to ", colourfile
        elif o == "--groupcolourfile":
            if colourfile:
                raise AttributeError("Can't specify both colourfile and groupcolourfile")
            groupcolourfile = a
        elif o == '--idfile':
            idfile = a
        elif o == '--shape':
            aspect = float(a)
        elif o == '--width':
            width = float(a)
        else:
            print "don't understand", o, a
            print ""
            usage()
            exit(1)
    
    
    groups = None
    
    if OPTIM:
        #make database from min.data ts.data
        db = Database()
        converter = OptimDBConverter(db)
        converter.convert_no_coords()
        groups = read_AB(db)
    else:
        if len(args) == 0:
            print "you must specify database file"
            print ""
            usage()
            exit()
        dbfile = args[0]
        if not os.path.exists(dbfile):
            print "database file doesn't exist", dbfile
            exit()
        
        db = Database(dbfile)
        
    if outfile is None and use_gui:
        app = QApplication(sys.argv) 
        kwargs["show_minima"] = False
        md = DGraphDialog(db, params=kwargs)
        md.rebuild_disconnectivity_graph()
        if groups is not None:
            md.dgraph_widget.dg.color_by_group(groups)
            md.dgraph_widget.redraw_disconnectivity_graph()
        md.show()
        sys.exit(app.exec_())
        
    # make graph from database
    t0 = time.time()
    if "Emax" in kwargs and use_gui:
        graph = reduced_db2graph(db, kwargs['Emax'])
    else:
        graph = dg.database2graph(db)
    t1 = time.time()
    print "loading the data into a transition state graph took", t1-t0, "seconds"

    # do the disconnectivity graph analysis
    mydg = dg.DisconnectivityGraph(graph, **kwargs)
    print "doing disconnectivity graph analysis"
    sys.stdout.flush()
    t1 = time.time()
    mydg.calculate()
    t2 = time.time()
    print "d-graph analysis finished in", t2-t1, "seconds"
    print "number of minima:", mydg.tree_graph.number_of_leaves()
    print "plotting disconnectivity graph"
    sys.stdout.flush()
    
    if colourfile:
        print "Colouring tree according to file ", colourfile
        colourfetcher = get_colours_from_file(db, colourfile)
        colouredtree = dg.ColorDGraphByValue(mydg.tree_graph,colourfetcher,normalize_values=True)
        print "tree set up"
        colouredtree.run()
        print "Finished colouring"
    elif groupcolourfile:
        print "Colouring tree according to file ", colourfile
        grouplists = get_group_lists(groupcolourfile)
        colouredtree = dg.ColorDGraphByGroups(mydg.tree_graph,grouplists)
        colouredtree.run()
        print "Finished colouring"
    
    if idfile:
        labelminima = []
        labels = {}
        fin = open(idfile,'r')
        for line in fin:
            minID = line.split()[0]
            labelminima.append(db.getMinimum(minID))
#            labels[labelminima[-1]]=str(labelminim
        fin.close()
        print "Labelling ", len(labelminima), "minima"

    print "Creating axes with dimensions ", width, width/aspect
    fig = plt.figure(figsize=(width, width/aspect))
    fig.set_facecolor('white')
    ax = fig.add_subplot(111, adjustable='box')

    # make the figure and save it
    mydg.plot(axes=ax)
    if idfile:
        print "Going into draw_minima"
        mydg.draw_minima(labelminima,labels=True)
    if outfile is None:
        plt.show()
    else:
        plt.savefig(outfile)
    t3 = time.time()
    print "plotting finished in", t3-t2, "seconds"
Exemple #20
0
def main():
    parser = argparse.ArgumentParser(
        description="""
convert an OPTIM database to a pele sqlite database.  Four files are needed.  Normally they are called:

    points.min : the coordinates of the minima in binary format
    min.data   : additional information about the minima (like the energy)
    points.ts  : the coordinates of the transition states
    min.ts     : additional information about transition states (like which minima they connect)

Other file names can optionally be passed.  Some fortran compilers use non-standard endianness to save the
binary data.  If your coordinates are garbage, try changing the endianness.
    """,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument(
        '--ndof',
        help=
        'Number of total degrees of freedom (e.g. 3*number of atoms).  This is simply the length of a coordinates vector.',
        type=int,
        default=None)
    parser.add_argument('--Database',
                        '-d',
                        help='Name of database to write into',
                        type=str,
                        default="optimdb.sqlite")
    parser.add_argument('--Mindata',
                        '-m',
                        help='Name of min.data file',
                        type=str,
                        default="min.data")
    parser.add_argument('--Tsdata',
                        '-t',
                        help='Name of ts.data file',
                        type=str,
                        default="ts.data")
    parser.add_argument('--Pointsmin',
                        '-p',
                        help='Name of points.min file',
                        type=str,
                        default="points.min")
    parser.add_argument('--Pointsts',
                        '-q',
                        help='Name of points.ts file',
                        type=str,
                        default="points.ts")
    parser.add_argument(
        '--endianness',
        help=
        'set the endianness of the binary data.  Can be "<" for little-endian or ">" for big-endian',
        type=str,
        default="=")
    args = parser.parse_args()

    db = Database(args.Database)

    cv = OptimDBConverter(database=db,
                          ndof=args.ndof,
                          mindata=args.Mindata,
                          tsdata=args.Tsdata,
                          pointsmin=args.Pointsmin,
                          pointsts=args.Pointsts,
                          endianness=args.endianness)

    cv.setAccuracy()

    cv.convert()
    cv.db.session.commit()