4
4
from collections import Counter
5
5
from typing import Dict , Optional , Union
6
6
7
+ import numpy as np
7
8
from moffragmentor import MOF as MOFFragmentorMOF # noqa: N811
8
9
from pymatgen .analysis .graphs import StructureGraph
9
10
from pymatgen .core import IStructure , Structure
@@ -39,6 +40,7 @@ def __init__(
39
40
describer_kwargs : Optional [Dict ] = None ,
40
41
incorporate_smiles : bool = True ,
41
42
describe_pores : bool = True ,
43
+ describe_rcsr : bool = True ,
42
44
) -> None :
43
45
"""Construct an instance of the MOFDescriber.
44
46
@@ -50,12 +52,15 @@ def __init__(
50
52
incorporate_smiles (bool): If True, describe building blocks.
51
53
describe_pores (bool): If True, add description of the geometry
52
54
of the MOF pores.
55
+ describe_rcsr (bool): If True, add RCSR code of the MOF
56
+ topology.
53
57
"""
54
58
describer_defaults = {"describe_oxidation_states" : False , "describe_bond_lengths" : True }
55
59
self .condenser_kwargs = condenser_kwargs or {}
56
60
self .describer_kwargs = {** describer_defaults , ** (describer_kwargs or {})}
57
61
self .incorporate_smiles = incorporate_smiles
58
62
self .describe_pores = describe_pores
63
+ self .describe_rcsr = describe_rcsr
59
64
60
65
def _get_bb_description (self , structure : Structure , structure_graph : StructureGraph ) -> str :
61
66
moffragmentor_mof = MOFFragmentorMOF (structure , structure_graph )
@@ -65,7 +70,21 @@ def _get_bb_description(self, structure: Structure, structure_graph: StructureGr
65
70
66
71
linker_smiles = " ," .join ("{} {}" .format (v , k ) for k , v in linker_counter .items ())
67
72
metal_smiles = " ," .join ("{} {}" .format (v , k ) for k , v in metal_counter .items ())
68
- return "Linkers: {}. Metal clusters: {}." .format (linker_smiles , metal_smiles )
73
+ bb_string = "Linkers: {}. Metal clusters: {}. " .format (linker_smiles , metal_smiles )
74
+
75
+ rcsr_code = fragments .net_embedding .rcsr_code
76
+ if rcsr_code and len (rcsr_code ) > 1 :
77
+ rcsr_string = "RCSR code: {}. " .format (rcsr_code )
78
+
79
+ output_string = ""
80
+ if self .incorporate_smiles :
81
+ output_string += bb_string
82
+ if self .describe_rcsr :
83
+ output_string += rcsr_string
84
+
85
+ return output_string
86
+
87
+ return output_string
69
88
70
89
def _get_pore_description (self , structure ):
71
90
pore_featurizer = MOFMultipleFeaturizer (
@@ -87,11 +106,15 @@ def _get_robocrys_description(self, structure):
87
106
88
107
def _featurize (self , structure : Structure , structure_graph : StructureGraph ):
89
108
description = self ._get_robocrys_description (structure )
90
- if self .incorporate_smiles :
91
- description += " " + self ._get_bb_description (structure , structure_graph )
109
+ if self .incorporate_smiles or self .describe_rcsr :
110
+ if description [- 1 ] != " " :
111
+ description += " "
112
+ description += self ._get_bb_description (structure , structure_graph )
92
113
if self .describe_pores :
93
- description += " " + self ._get_pore_description (structure )
94
- return description
114
+ if description [- 1 ] != " " :
115
+ description += " "
116
+ description += self ._get_pore_description (structure )
117
+ return np .array ([description ])
95
118
96
119
def featurize (self , structure : Union [Structure , IStructure ]):
97
120
return self ._featurize (structure , get_sg (structure ))
0 commit comments