Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make BBs pormake compatible #156

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.4-dev
current_version = 0.0.5-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-]+)*))?
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.4-dev"
release = "0.0.5-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.4-dev
version = 0.0.5-dev
description = Splits MOFs into metal nodes and linkers.
author = Kevin Maik Jablonka
author_email = [email protected]
Expand Down
50 changes: 38 additions & 12 deletions src/moffragmentor/sbu/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

_BINDING_DUMMY = "Xe"
_BRANCHING_DUMMY = "Kr"
_EXTENSION_DUMMY = "Ar" # important for MOF assembly tools


def _build_mol_and_graph(mof, indices, ignore_hidden_indices=True, add_additional_site=True):
Expand Down Expand Up @@ -77,54 +78,79 @@ def _extract_and_wrap(node_indices, all_branching_indices, all_binding_indices,
# now, also create one molecule from the node indices, where we replace
# binding and branching indices with dummy atoms
node_metal_atoms = [i for i in node_indices if i in mof.metal_indices]
binding_to_node_metal = set(sum([mof.get_neighbor_indices(i) for i in node_metal_atoms], []))
binding_to_node_metal = binding_to_node_metal.intersection(all_binding_indices)
metal_neighbors = set(sum([mof.get_neighbor_indices(i) for i in node_metal_atoms], []))
binding_to_node_metal = metal_neighbors.intersection(all_binding_indices)

branching_to_node_metal = set(
sum(
[mof.get_neighbor_indices(i) for i in node_metal_atoms if i in all_branching_indices],
[],
)
)
branching_to_node_metal = (metal_neighbors & all_branching_indices) - set(node_metal_atoms)

print(branching_to_node_metal, all_branching_indices)
binding_neighbors = sum([mof.get_neighbor_indices(i) for i in binding_to_node_metal], [])
branching_to_binding = set(binding_neighbors).intersection(all_branching_indices)

extension_points = []

for branching_idx in branching_to_binding | branching_to_node_metal:
if branching_idx in node_indices:
# find extension point
neighbors_of_branching = mof.get_neighbor_indices(branching_idx)
extension_point = set(neighbors_of_branching) - node_indices
# assert len(extension_point) == 1 # perhaps we should raise an error here
extension_point = list(extension_point)[0]
extension_points.append(extension_point)
else:
extension_points.append(branching_idx)

# Now, make a copy of the structure and replace the indices with dummy atoms
dummy_structure = Structure.from_sites(mof.structure.sites)
print("binding_to_node_metal", binding_to_node_metal)
for i in binding_to_node_metal:
dummy_structure.replace(i, _BINDING_DUMMY)
for i in branching_to_binding | branching_to_node_metal:
dummy_structure.replace(i, _BRANCHING_DUMMY)
dummy_branching_sites = branching_to_binding | branching_to_node_metal
for i in extension_points:
dummy_structure.replace(i, _EXTENSION_DUMMY)
dummy_branching_sites = branching_to_binding | branching_to_node_metal | set(extension_points)
mol_w_dummy, graph_w_dummy, mapping_w_dummy = _build_mol_and_graph(
mof,
list(node_indices)
+ list(binding_to_node_metal)
+ list(branching_to_binding)
+ list(branching_to_node_metal),
+ list(branching_to_node_metal)
+ extension_points,
ignore_hidden_indices=False,
add_additional_site=False,
)

inverse_mapping = {v[0]: k for k, v in mapping_w_dummy.items()}
print("inverse_mapping", inverse_mapping)
# let's replace here now the atoms with the dummys as doing it beforehand might cause issues
# (e.g. we do not have the distances for a cutoffdict)

original_mol_w_dummy_species = mol_w_dummy.species
for i in branching_to_binding | branching_to_node_metal:
if i not in node_indices & set(mof.metal_indices):
mol_w_dummy._sites[inverse_mapping[i]] = Site(
_BRANCHING_DUMMY,
mol_w_dummy._sites[inverse_mapping[i]].coords,
properties={"original_species": str(mol_w_dummy._sites[inverse_mapping[i]].specie)},
properties={
"original_species": str(original_mol_w_dummy_species[inverse_mapping[i]])
},
)

for i in binding_to_node_metal:
mol_w_dummy._sites[inverse_mapping[i]] = Site(
_BINDING_DUMMY,
mol_w_dummy._sites[inverse_mapping[i]].coords,
properties={"original_species": str(mol_w_dummy._sites[inverse_mapping[i]].specie)},
properties={"original_species": str(original_mol_w_dummy_species[inverse_mapping[i]])},
)

# for i in extension_points:
# mol_w_dummy._sites[inverse_mapping[i]] = Site(
# _EXTENSION_DUMMY,
# mol_w_dummy._sites[inverse_mapping[i]].coords,
# properties={"original_species": str(original_mol_w_dummy_species[inverse_mapping[i]])},
# )

graph_w_dummy.molecule = mol_w_dummy

return mol, graph, mapping, mol_w_dummy, graph_w_dummy, mapping_w_dummy, dummy_branching_sites
Expand Down
5 changes: 5 additions & 0 deletions src/moffragmentor/sbu/sbu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pymatgen.core import Molecule, Structure
from pymatgen.io.babel import BabelMolAdaptor
from rdkit import Chem
from rdkit.Chem.Descriptors import NumRadicalElectrons
from scipy.spatial.distance import pdist

from moffragmentor.utils import pickle_dump
Expand Down Expand Up @@ -210,6 +211,10 @@ def get_indices(self):
def is_edge(self):
return len(self.branching_coords) == 2

@property
def num_radical_electrons(self):
return NumRadicalElectrons(self.rdkit_mol)

def __len__(self):
"""Return the number of atoms in the molecule."""
return len(self.molecule)
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.4-dev"
VERSION = "0.0.5-dev"


def get_git_hash() -> str:
Expand Down