Skip to content

Commit

Permalink
Add method to create a graph from jumps
Browse files Browse the repository at this point in the history
  • Loading branch information
stefsmeets committed Jun 4, 2024
1 parent 4972d1a commit 3fbe456
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/gemdat/jumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from math import ceil
from typing import TYPE_CHECKING, Callable

import networkx as nx
import numpy as np
import pandas as pd
from pymatgen.core.units import FloatWithUnit
Expand Down Expand Up @@ -308,6 +309,41 @@ def jumps_counter(self) -> Counter:
)
return jumps

def activation_energy_between_sites(self, start: str, stop: str) -> float:
raise NotImplementedError

def to_graph(self) -> nx.DiGraph:
"""Create a graph from jumps data.
The edges are weighted by the activation energy.
Returns
-------
G : nx.DiGraph
A networkx DiGraph object.
"""
atom_percentage = {
site.label: site.species.num_atoms for site in self.transitions.occupancy()
}

attempt_freq, _ = self.trajectory.metrics().attempt_frequency()
temperature = self.trajectory.metadata['temperature']
kBT = Boltzmann * temperature

G = nx.DiGraph()

for (start, stop), n_jumps in self.jumps_counter().items():
time_perc = atom_percentage[start] * self.trajectory.total_time

eff_rate = n_jumps / time_perc

e_act = -np.log(eff_rate / attempt_freq) * kBT
e_act /= elementary_charge

G.add_edge(start, stop, e_act=e_act)

return G

def split(self, n_parts: int) -> list[Jumps]:
"""Split the jumps into parts.
Expand Down
7 changes: 7 additions & 0 deletions src/gemdat/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
if TYPE_CHECKING:
from pymatgen.core import Structure

from .metrics import SimulationMetrics
from .transitions import Transitions
from .volume import Volume

Expand Down Expand Up @@ -520,6 +521,12 @@ def transitions_between_sites(
site_inner_fraction=site_inner_fraction,
)

def metrics(self) -> SimulationMetrics:
"""See [gemdat.SimulationMetrics][] for more info."""
from .metrics import SimulationMetrics

return SimulationMetrics(trajectory=self)

def plot_displacement_per_atom(self, **kwargs):
"""See [gemdat.plots.displacement_per_atom][] for more info."""
from gemdat import plots
Expand Down

0 comments on commit 3fbe456

Please sign in to comment.