Skip to content

Commit

Permalink
feat: return more info about the fragmentation fallbacks
Browse files Browse the repository at this point in the history
- log if we find a >0d node 
- implement interface for branching site structure
  • Loading branch information
kjappelbaum committed Dec 24, 2022
1 parent b6d6507 commit 96c5e2b
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 22 deletions.
14 changes: 7 additions & 7 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[bumpversion]
current_version = 0.0.5-dev
current_version = 0.0.6-dev
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(?:-(?P<release>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+(?P<build>[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?
serialize =
{major}.{minor}.{patch}-{release}+{build}
{major}.{minor}.{patch}+{build}
{major}.{minor}.{patch}-{release}
{major}.{minor}.{patch}
{major}.{minor}.{patch}-{release}+{build}
{major}.{minor}.{patch}+{build}
{major}.{minor}.{patch}-{release}
{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = production
first_value = dev
values =
dev
production
dev
production

[bumpverion:part:build]
values = [0-9A-Za-z-]+
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
author = "Kevin Maik Jablonka"

# The full version, including alpha/beta/rc tags
release = "0.0.5-dev"
release = "0.0.6-dev"


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = moffragmentor
version = 0.0.5-dev
version = 0.0.6-dev
description = Splits MOFs into metal nodes and linkers.
author = Kevin Maik Jablonka
author_email = mail@kjablonka.com
Expand Down
2 changes: 1 addition & 1 deletion src/moffragmentor/fragmentor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def run_fragmentation(
try:
not_node = []
logger.debug(f"Fragmenting MOF for the {counter} time")
node_result, node_collection = find_nodes(
node_result, node_collection, has_1d_sbu = find_nodes(
mof,
unbound_solvent,
forbidden_indices,
Expand Down
9 changes: 6 additions & 3 deletions src/moffragmentor/fragmentor/nodelocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@ def create_single_metal_nodes(mof, node_result):
def break_rod_nodes(mof, node_result):
"""Break rod nodes into smaller pieces."""
new_nodes = []
broke_nodes = False
for node in node_result.nodes:
if get_sbu_dimensionality(mof, node) >= 1:
logger.debug("Found 1- or 2-dimensional node. Will break into isolated metals.")
new_nodes.extend(break_rod_node(mof, node))
broke_nodes = True
else:
new_nodes.append(node)
new_node_result = NodelocationResult(
Expand All @@ -228,7 +230,7 @@ def break_rod_nodes(mof, node_result):
node_result.binding_indices,
node_result.to_terminal_from_branching,
)
return new_node_result
return new_node_result, broke_nodes


def check_node(node_indices, branching_indices, mof) -> bool:
Expand Down Expand Up @@ -300,6 +302,7 @@ def find_nodes(
Returns:
NodeCollection: collection of nodes
"""
broke_rod_nodes = None
if forbidden_indices is None:
forbidden_indices = []

Expand All @@ -311,14 +314,14 @@ def find_nodes(
node_result = create_single_metal_nodes(mof, node_result)
if check_dimensionality:
# If we have nodes with dimensionality >0, we change these nodes to only contain the metal
node_result = break_rod_nodes(mof, node_result)
node_result, broke_rod_nodes = break_rod_nodes(mof, node_result)
if break_organic_nodes_:
# ToDo: This, of course, would also break prophyrin ...
node_result = break_organic_nodes(node_result, mof)

node_collection = create_node_collection(mof, node_result)

return node_result, node_collection
return node_result, node_collection, broke_rod_nodes


def metal_and_branching_coplanar(node_idx, all_branching_idx, mof, tol=0.1):
Expand Down
5 changes: 3 additions & 2 deletions src/moffragmentor/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,9 @@ def build_net(
edge_selection.append(edges[0][0])
else:
# sort ascending by second element in tuple in the list
edge_selection.append(sorted(edges, key=lambda x: x[1])[0][0])

selected_edges = [e[0] for e in sorted(edges, key=lambda x: x[1])]
edge_selection.extend(selected_edges) # sorted(edges, key=lambda x: x[1])[0][0])
# edge_selection.extend(sorted(edges, key=lambda x: x[1])[0][0])
for edge in edge_selection:
if not contains_edge(edge, found_edges):
found_edges.append(edge)
Expand Down
17 changes: 16 additions & 1 deletion src/moffragmentor/sbu/linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Describing the organic building blocks, i.e., linkers."""
from copy import deepcopy

from pymatgen.core import Molecule
from pymatgen.core import Molecule, PeriodicSite, Structure
from rdkit.Chem import AllChem

from .sbu import SBU
Expand All @@ -15,6 +15,21 @@ def __repr__(self) -> str:
"""Return a string representation of the linker."""
return f"Linker ({self.composition})"

def _get_branching_sites_structure(self) -> Structure:
new_sites = []
s = self._get_boxed_structure()
for i, site in enumerate(s):
if set([self.mapping_to_original_indices[i]]) & self.original_graph_branching_indices:
if "original_species" in site.properties and site.properties["original_species"]:
species = site.properties["original_species"]
else:
species = site.species

new_site = PeriodicSite(species, site.coords, site.lattice)
new_sites.append(new_site)

return Structure.from_sites(new_sites)


def _get_edge_dict_from_rdkit_mol(mol):
edges = {}
Expand Down
27 changes: 22 additions & 5 deletions src/moffragmentor/sbu/sbu.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from backports.cached_property import cached_property
from loguru import logger
from pymatgen.analysis.graphs import MoleculeGraph
from pymatgen.core import Molecule, Structure
from pymatgen.core import Molecule, PeriodicSite, Structure
from pymatgen.io.babel import BabelMolAdaptor
from rdkit import Chem
from scipy.spatial.distance import pdist
Expand Down Expand Up @@ -378,23 +378,40 @@ def smiles(self) -> str:
except Exception:
return smiles

def _get_boxed_structure(self):
max_size = _get_max_sep(self.molecule.cart_coords)
structure = self.molecule.get_boxed_structure(
def _get_boxed_structure(self, mol=None) -> Structure:
if mol is None:
mol = self.molecule
max_size = _get_max_sep(mol.cart_coords)
structure = mol.get_boxed_structure(
max_size + 0.1 * max_size,
max_size + 0.1 * max_size,
max_size + 0.1 * max_size,
reorder=False,
)
return structure

def _get_binding_sites_structure(self):
def _get_binding_sites_structure(self) -> Structure:
sites = []
s = self._get_boxed_structure()
for i in self.binding_indices:
sites.append(s[i])
return Structure.from_sites(sites)

def _get_branching_sites_structure(self) -> Structure:
new_sites = []
s = self._get_boxed_structure(self._dummy_molecule)
for i, site in enumerate(s):
if set(self._dummy_molecule_indices_mapping[i]) & self._dummy_branching_indices:
if "original_species" in site.properties and site.properties["original_species"]:
species = site.properties["original_species"]
else:
species = site.species

new_site = PeriodicSite(species, site.coords, site.lattice)
new_sites.append(new_site)

return Structure.from_sites(new_sites)

@cached_property
def descriptors(self):
return self._get_descriptors()
Expand Down
2 changes: 1 addition & 1 deletion src/moffragmentor/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"get_git_hash",
]

VERSION = "0.0.5-dev"
VERSION = "0.0.6-dev"


def get_git_hash() -> str:
Expand Down

0 comments on commit 96c5e2b

Please sign in to comment.