def test_disconn_graph(self,database): from pygmin.utils.disconnectivity_graph import DisconnectivityGraph from pygmin.landscape import TSGraph import matplotlib.pyplot as plt graph = TSGraph(database).graph dg = DisconnectivityGraph(graph, nlevels=3, center_gmin=True) dg.calculate() dg.plot() plt.show()
def _build_list(self): print "populating list of minima not connected to the global minimum" self.minpairs = deque() gmin = self.database.minima()[0] graph = TSGraph(self.database) for m in self.database.minima()[1:]: if not graph.areConnected(gmin, m): if self.is_good_pair(gmin, m): self.minpairs.append((gmin, m))
def _build_disconnectivity_graph(self, **params): if self.database is None: graph = self.graph else: db = self.database if self.params.has_key('Emax'): graph = reduced_db2graph(db, params['Emax']) else: graphwrapper = TSGraph(db) graph = graphwrapper.graph dg = DisconnectivityGraph(graph, **params) dg.calculate() self.dg = dg
def make_graph(self, database=None, minima=None): if database is None: database = self.database if minima is None: minima = self.minima print "making graph", database, minima #get the graph object, eliminate nodes without edges graphwrapper = TSGraph(database, minima) graph = graphwrapper.graph print graph.number_of_nodes() degree = graph.degree() nodes = [n for n, nedges in degree.items() if nedges > 0] self.graph = graph.subgraph(nodes) print self.graph.number_of_nodes(), self.graph.number_of_edges()
def _build_list(self): """make a list of minima pairs to try to connect""" print "analyzing the database to find minima to connect" self.minpairs = deque() graph = TSGraph(self.database).graph cclist = nx.connected_components(graph) # remove clusters with fewer than clust_min cclist = [cc for cc in cclist if len(cc) >= self.clust_min] if len(cclist) == 0: print "all minima are connected" return self.minpairs # get the group that all other groups will be connected to group1 = cclist[0] min1 = sorted(group1, key=lambda m: m.energy)[0] if True: # make sure that the global minimum is in group1 global_min = self.database.minima()[0] if not global_min in group1: print "warning, the global minimum is not the in the largest cluster. Will try to connect them" self.minpairs.append((min1, global_min)) # remove group1 from cclist cclist.remove(group1) # get a minima from each of the other groups for group2 in cclist: if len(self.minpairs) > self.list_len: break print "adding groups of size", len(group1), "and", len( group2), "to the connect list" # sort the groups by energy group2.sort(key=lambda m: m.energy) # select the lowest energy minima in the groups # (this can probably be done in a more intelligent way) min2 = group2[0] if self.is_good_pair(min1, min2): self.minpairs.append((min1, min2)) return self.minpairs
def make_graph(database): #make a graph from the database graphwrapper = TSGraph(db) #turn the graph into a disconnectivity graph mydg = dg.DisconnectivityGraph( graphwrapper.graph, nlevels=5, center_gmin=False, order_by_energy=True, # Emax=-169. ) mydg.calculate() print "number of minima:", mydg.tree_graph.number_of_leaves() mydg.plot() plt.show()
def get_next_pair_gmin(self): minima = self.database.minima() min1 = minima[0] graph = TSGraph(self.database) all_connected = True for m2 in minima[1:]: if not graph.areConnected(min1, m2): if (min1, m2) in self.failed_pairs or ( m2, min1) in self.failed_pairs: continue all_connected = False break if all_connected: print "minima are all connected, ending" self.textEdit_summary.insertPlainText( "minima are all connected, ending\n") return None, None return min1, m2
def on_btn_connect_in_optim_clicked(self, clicked=None): """spawn an OPTIM job and retrieve the minima and transition states it finds""" if clicked is None: return min1, min2 = self.get_selected_minima() # existing_minima = set(self.system.database.minima()) spawner = self.system.get_optim_spawner(min1.coords, min2.coords) spawner.run() db = self.system.database newminima, newts = spawner.load_results(self.system.database) # for m in newminima: # if m not in existing_minima: # self.NewMinimum(m) #now use DoubleEndedConnect to test if they are connected graph = TSGraph(db) if graph.areConnected(min1, min2): #use double ended connect to draw the interpolated path #this is ugly self._doubleEndedConnect(reconnect=False, min1min2=(min1, min2))
def mytest(nmin=40, natoms=13): from pygmin.landscape import DoubleEndedConnect from pygmin.landscape._graph import create_random_database from pygmin.mindist import minPermDistStochastic, MinDistWrapper from pygmin.potentials import LJ from pygmin.landscape import TSGraph pot = LJ() mindist = MinDistWrapper(minPermDistStochastic, permlist=[range(natoms)], niter=10) db = create_random_database(nmin=nmin, natoms=natoms) min1, min2 = list(db.minima())[:2] graph = TSGraph(db) connect = DoubleEndedConnect(min1, min2, pot, mindist, db, use_all_min=True, merge_minima=True, max_dist_merge=.1)
def _build_list(self): print "using disconnectivity analysis to find minima to untrap" self.minpairs = deque() graph = TSGraph(self.database).graph cclist = nx.connected_components(graph) # get the largest cluster group1 = cclist[0] min1 = sorted(group1, key=lambda m: m.energy)[0] if not min1 == self.database.minima()[0]: # make sure that the global minimum is in group1 print "warning, the global minimum is not the in the largest cluster." # compute the energy barriers for all minima in the cluster subgraph = nx.subgraph(graph, group1) energy_barriers = self._compute_barriers(subgraph, min1) # sort the minima by the barrier height divided by the energy difference weights = [(m, np.abs(barrier) / np.abs(m.energy - min1.energy)) for (m, barrier) in energy_barriers.iteritems()] weights.sort(key=lambda v: 1. / v[1]) self.minpairs = deque() for min2, w in weights: if len(self.minpairs) > self.list_len: break if not self.is_good_pair(min1, min2): continue self.minpairs.append((min1, min2)) if True: # print some stuff print " untrap analysis: minimum", min2._id, "with energy", min2.energy, "barrier", energy_barriers[ min2], "untrap weight", w
def database2graph(database): """create a networkx graph from a pygmin database""" from pygmin.landscape import TSGraph # this must be imported here to avoid circular imports graph_wrapper = TSGraph(database) return graph_wrapper.graph
if (not min1 is minimum and not min2 is minimum): print "Warning in single ended search: did not find initial minimum during quench from transition state" if (min1 is min2): print "Warning in single ended search: downhill search from transistion state ended in same minimum" ts = graph.addTransitionState(energy_ts, x_ts, min1, min2) print "found transition state: ", min1._id, min2._id, min1.energy, ts.energy, min2.energy search.findNextTS() if __name__ == "__main__": from pygmin.landscape import TSGraph from connect_min import getSetOfMinLJ natoms = 8 pot, saveit = getSetOfMinLJ(natoms) graph = TSGraph(saveit) minima = saveit.minima() find_escape_paths(minima[0], pot, graph, ntries=20) #print graph #for node in graph.graph.nodes(): # print node, node.energy for ts in graph.storage.transition_states(): print ts.minimum1._id, ts.minimum2._id, "E", ts.minimum1.energy, ts.minimum2.energy, ts.minimum2.energy
from pygmin.utils.disconnectivity_graph import DisconnectivityGraph from pygmin.storage import Database from pygmin.landscape import TSGraph import pylab as pl import numpy as np kbT = 0.75 db = Database(db="tip4p_8.sqlite", createdb=False) graph = TSGraph(db) dg = DisconnectivityGraph(graph.graph, db.minima(), subgraph_size=20) dg.calculate() dg.plot() for m in db.minima(): if m.pgorder != 2: print m.pgorder m.free_energy = m.energy + kbT * 0.5 * m.fvib + kbT * np.log(m.pgorder) for ts in db.transition_states(): # if ts.pgorder != 2: print ts.pgorder #assert ts.pgorder == 2 ts.free_energy = ts.energy + kbT * 0.5 * ts.fvib + kbT * np.log( ts.pgorder) + kbT * np.log(kbT) if ts.free_energy > ts.minimum1.free_energy or ts.free_energy > ts.minimum2.free_energy: print "warning, free energy of transition state lower than minimum" print ts.free_energy, ts.minimum1.free_energy, ts.minimum2.free_energy
def __init__(self, min1, min2, pot, mindist, database, use_all_min=False, verbosity=1, merge_minima=False, max_dist_merge=0.1, local_connect_params=dict(), fresh_connect=False, longest_first=True, niter=200, conf_checks=None, load_no_distances=False): self.minstart = min1 assert min1._id == min1, "minima must compare equal with their id %d %s %s" % ( min1._id, str(min1), str(min1.__hash__())) self.minend = min2 self.pot = pot self.mindist = mindist self.pairsNEB = dict() self.longest_first = longest_first self.niter = niter if conf_checks is None: self.conf_checks = [] else: self.conf_checks = conf_checks self.verbosity = int(verbosity) self.local_connect_params = dict([("verbosity", verbosity)] + local_connect_params.items()) self.database = database self.fresh_connect = fresh_connect if self.fresh_connect: self.graph = TSGraph(self.database, minima=[self.minstart, self.minend], no_edges=True) else: self.graph = TSGraph(self.database) self.merge_minima = merge_minima self.max_dist_merge = float(max_dist_merge) self.load_no_distances = load_no_distances self.dist_graph = _DistanceGraph(self.database, self.graph, self.mindist, self.verbosity) #check if a connection exists before initializing distance graph if self.graph.areConnected(self.minstart, self.minend): logger.info( "minima are already connected. not initializing distance graph" ) return self.dist_graph.initialize(self.minstart, self.minend, use_all_min=use_all_min, load_no_distances=self.load_no_distances) if self.verbosity > 0: logger.info( "************************************************************") logger.info("starting a double ended connect run between") logger.info(" minimum 1: id %d energy %f" % (self.minstart._id, self.minstart.energy)) logger.info(" minimum 2: id %d energy %f" % (self.minend._id, self.minend.energy)) logger.info(" dist %f" % self.getDist(self.minstart, self.minend)) logger.info( "************************************************************")
def make_disconnectivity_graph(database): graph = TSGraph(database).graph dg = DisconnectivityGraph(graph, nlevels=3, center_gmin=True) dg.calculate() dg.plot() plt.show()