molcraft 0.1.0a16__py3-none-any.whl → 0.1.0a17__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of molcraft might be problematic. Click here for more details.

molcraft/layers.py CHANGED
@@ -1441,7 +1441,7 @@ class AddContext(GraphLayer):
1441
1441
  def __init__(
1442
1442
  self,
1443
1443
  field: str = 'feature',
1444
- drop: bool = True,
1444
+ drop: bool = False,
1445
1445
  normalize: bool = False,
1446
1446
  **kwargs
1447
1447
  ) -> None:
molcraft/models.py CHANGED
@@ -154,6 +154,7 @@ class GraphModel(layers.GraphLayer, keras.models.Model):
154
154
  return graph
155
155
 
156
156
  def get_config(self):
157
+ """Obtain model config."""
157
158
  config = super().get_config()
158
159
  if hasattr(self, '_model_layers') and self._model_layers is not None:
159
160
  config['model_layers'] = [
@@ -164,6 +165,7 @@ class GraphModel(layers.GraphLayer, keras.models.Model):
164
165
 
165
166
  @classmethod
166
167
  def from_config(cls, config: dict):
168
+ """Obtain model from model config."""
167
169
  if 'model_layers' in config:
168
170
  config['model_layers'] = [
169
171
  keras.saving.deserialize_keras_object(l)
molcraft/records.py CHANGED
@@ -14,7 +14,7 @@ from molcraft import featurizers
14
14
 
15
15
  def write(
16
16
  inputs: list[str | tuple],
17
- featurizer: featurizers.Featurizer,
17
+ featurizer: featurizers.GraphFeaturizer,
18
18
  path: str,
19
19
  overwrite: bool = True,
20
20
  num_files: typing.Optional[int] = None,
@@ -23,10 +23,13 @@ def write(
23
23
  device: str = '/cpu:0'
24
24
  ) -> None:
25
25
 
26
- if os.path.isdir(path) and not overwrite:
27
- return
28
-
29
- os.makedirs(path, exist_ok=True)
26
+ if os.path.isdir(path):
27
+ if not overwrite:
28
+ return
29
+ else:
30
+ _remove_files(path)
31
+ else:
32
+ os.makedirs(path)
30
33
 
31
34
  with tf.device(device):
32
35
 
@@ -133,7 +136,7 @@ def load_spec(path: str) -> tensors.GraphTensor.Spec:
133
136
  def _write_tfrecord(
134
137
  inputs,
135
138
  path: str,
136
- featurizer: featurizers.Featurizer,
139
+ featurizer: featurizers.GraphFeaturizer,
137
140
  ) -> None:
138
141
 
139
142
  def _write_example(tensor):
@@ -149,11 +152,7 @@ def _write_tfrecord(
149
152
  x = tuple(x)
150
153
  tensor = featurizer(x)
151
154
  if tensor is not None:
152
- if isinstance(tensor, tensors.GraphTensor):
153
- _write_example(tensor)
154
- else:
155
- for t in tensor:
156
- _write_example(t)
155
+ _write_example(tensor)
157
156
 
158
157
  def _serialize_example(
159
158
  feature: dict[str, tf.train.Feature]
@@ -168,8 +167,18 @@ def _parse_example(
168
167
  ) -> tf.Tensor:
169
168
  out = tf.io.parse_single_example(
170
169
  x, features={'feature': tf.io.RaggedFeature(tf.string)})['feature']
171
- out = [tf.ensure_shape(tf.io.parse_tensor(x[0], s.dtype), s.shape) for (x, s) in zip(
172
- tf.split(out, len(tf.nest.flatten(spec, expand_composites=True))),
173
- tf.nest.flatten(spec, expand_composites=True))]
170
+ out = [
171
+ tf.ensure_shape(tf.io.parse_tensor(x[0], s.dtype), s.shape)
172
+ for (x, s) in zip(
173
+ tf.split(out, len(tf.nest.flatten(spec, expand_composites=True))),
174
+ tf.nest.flatten(spec, expand_composites=True)
175
+ )
176
+ ]
174
177
  out = tf.nest.pack_sequence_as(spec, tf.nest.flatten(out), expand_composites=True)
175
- return out
178
+ return out
179
+
180
+ def _remove_files(path):
181
+ for filename in os.listdir(path):
182
+ if filename.endswith('tfrecord') or filename == 'spec.pb':
183
+ filepath = os.path.join(path, filename)
184
+ os.remove(filepath)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: molcraft
3
- Version: 0.1.0a16
3
+ Version: 0.1.0a17
4
4
  Summary: Graph Neural Networks for Molecular Machine Learning
5
5
  Author-email: Alexander Kensert <alexander.kensert@gmail.com>
6
6
  License: MIT License
@@ -43,9 +43,9 @@ Provides-Extra: gpu
43
43
  Requires-Dist: tensorflow[and-cuda]>=2.16; extra == "gpu"
44
44
  Dynamic: license-file
45
45
 
46
- <img src="https://github.com/akensert/molcraft/blob/main/docs/_static/molcraft-logo.png" alt="molcraft-logo">
46
+ <img src="https://github.com/akensert/molcraft/blob/main/docs/_static/molcraft-logo.png" alt="molcraft-logo", width="90%">
47
47
 
48
- **Deep Learning on Molecules**: A Minimalistic GNN package for Molecular ML.
48
+ **Deep Learning on Molecules**: A Minimalistic GNN package for Molecular ML.
49
49
 
50
50
  > [!NOTE]
51
51
  > In progress.
@@ -83,11 +83,12 @@ featurizer = featurizers.MolGraphFeaturizer(
83
83
  features.BondType(),
84
84
  features.IsRotatable(),
85
85
  ],
86
- super_atom=True,
86
+ super_node=True,
87
87
  self_loops=True,
88
+ include_hydrogens=False,
88
89
  )
89
90
 
90
- graph = featurizer([('N[C@@H](C)C(=O)O', 2.0), ('N[C@@H](CS)C(=O)O', 1.0)])
91
+ graph = featurizer([('N[C@@H](C)C(=O)O', 2.5), ('N[C@@H](CS)C(=O)O', 1.5)])
91
92
  print(graph)
92
93
 
93
94
  model = models.GraphModel.from_layers(
@@ -95,13 +96,13 @@ model = models.GraphModel.from_layers(
95
96
  layers.Input(graph.spec),
96
97
  layers.NodeEmbedding(dim=128),
97
98
  layers.EdgeEmbedding(dim=128),
98
- layers.GraphTransformer(units=128),
99
- layers.GraphTransformer(units=128),
100
- layers.GraphTransformer(units=128),
101
- layers.GraphTransformer(units=128),
102
- layers.Readout(mode='mean'),
103
- keras.layers.Dense(units=1024, activation='relu'),
104
- keras.layers.Dense(units=1024, activation='relu'),
99
+ layers.GraphConv(units=128),
100
+ layers.GraphConv(units=128),
101
+ layers.GraphConv(units=128),
102
+ layers.GraphConv(units=128),
103
+ layers.Readout(),
104
+ keras.layers.Dense(units=1024, activation='elu'),
105
+ keras.layers.Dense(units=1024, activation='elu'),
105
106
  keras.layers.Dense(1)
106
107
  ]
107
108
  )
@@ -0,0 +1,21 @@
1
+ molcraft/__init__.py,sha256=vc-z1sgtzPY7Spwzkemu7I_b9ekEN9egnHrLEKbB9bk,431
2
+ molcraft/callbacks.py,sha256=x5HnkZhqcFRrW6xdApt_jZ4X08A-0fxcnFKfdmRKa0c,3571
3
+ molcraft/chem.py,sha256=e56qBDuqh8rq_4-UMyp6LCQNxxSx8hZ7gzuz-87DHgw,21652
4
+ molcraft/datasets.py,sha256=Nd2lw5USUZE52vvAiNr-q-n03Y3--NlZlK0NzqHgp-E,4145
5
+ molcraft/descriptors.py,sha256=Cl3KnBPsTST7XLgRLktkX5LwY9MV0P_lUlrt8iPV5no,3508
6
+ molcraft/features.py,sha256=s0WeV8eZcDEypPgC1m37f4s9QkvWIlVgn-L43Cdsa14,13525
7
+ molcraft/featurizers.py,sha256=bD3RFY9eg89-O-Nxgy6gote1zS4cyjOgzdSiSJZJdJE,17664
8
+ molcraft/layers.py,sha256=Y-TMb4oHh3R7tHgr7f3Y8sEPDnoSTbtwB6NkZIVnmcA,61734
9
+ molcraft/losses.py,sha256=qnS2yC5g-O3n_zVea9MR6TNiFraW2yqRgePOisoUP4A,1065
10
+ molcraft/models.py,sha256=2Pc1htT9fCukGd8ZxrvE0rzEHsPBm0pluHw4FZXaUE4,21963
11
+ molcraft/ops.py,sha256=bQbdFDt9waxVCzF5-dkTB6vlpj9eoSt8I4Qg7ZGXbsU,6178
12
+ molcraft/records.py,sha256=0j4EWP55sfnkoQIH5trdaAIevPfVbAtPLrygTRmLyFw,5686
13
+ molcraft/tensors.py,sha256=EOUKx496KUZsjA1zA2ABc7tU_TW3Jv7AXDsug_QsLbA,22407
14
+ molcraft/applications/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
+ molcraft/applications/chromatography.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ molcraft/applications/proteomics.py,sha256=Jb7OwHJHc_I7Wk3qnqr40j9P7um2EKtUnB4r-XhrnAc,7180
17
+ molcraft-0.1.0a17.dist-info/licenses/LICENSE,sha256=sbVeqlrtZ0V63uYhZGL5dCxUm8rBAOqe2avyA1zIQNk,1074
18
+ molcraft-0.1.0a17.dist-info/METADATA,sha256=XqNJDwFfY6pWNqQKYLyUOxwyvmfYUkOWTKou-ZQYXL4,3930
19
+ molcraft-0.1.0a17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
+ molcraft-0.1.0a17.dist-info/top_level.txt,sha256=dENV6MfOceshM6MQCgJlcN1ojZkiCL9B4F7XyUge3QM,9
21
+ molcraft-0.1.0a17.dist-info/RECORD,,
molcraft/conformers.py DELETED
@@ -1,151 +0,0 @@
1
- import keras
2
-
3
- from molcraft import chem
4
-
5
-
6
- @keras.saving.register_keras_serializable(package="molcraft")
7
- class ConformerProcessor:
8
-
9
- def get_config(self) -> dict:
10
- return {}
11
-
12
- @classmethod
13
- def from_config(cls, config: dict):
14
- return cls(**config)
15
-
16
- def __call__(self, mol: chem.Mol) -> chem.Mol:
17
- raise NotImplementedError
18
-
19
-
20
- @keras.saving.register_keras_serializable(package="molcraft")
21
- class ConformerEmbedder(ConformerProcessor):
22
-
23
- def __init__(
24
- self,
25
- method: str = 'ETKDGv3',
26
- num_conformers: int = 5,
27
- **kwargs,
28
- ) -> None:
29
- self.method = method
30
- self.num_conformers = num_conformers
31
- self.kwargs = kwargs
32
-
33
- def get_config(self) -> dict:
34
- config = {
35
- 'method': self.method,
36
- 'num_conformers': self.num_conformers,
37
- }
38
- config.update({
39
- k: v for (k, v) in self.kwargs.items()
40
- })
41
- return config
42
-
43
- def __call__(self, mol: chem.Mol) -> chem.Mol:
44
- return chem.embed_conformers(
45
- mol,
46
- method=self.method,
47
- num_conformers=self.num_conformers,
48
- **self.kwargs,
49
- )
50
-
51
-
52
- @keras.saving.register_keras_serializable(package="molcraft")
53
- class ConformerOptimizer(ConformerProcessor):
54
-
55
- def __init__(
56
- self,
57
- method: str = 'UFF',
58
- max_iter: int = 200,
59
- ignore_interfragment_interactions: bool = True,
60
- vdw_threshold: float = 10.0,
61
- **kwargs,
62
- ) -> None:
63
- self.method = method
64
- self.max_iter = max_iter
65
- self.ignore_interfragment_interactions = ignore_interfragment_interactions
66
- self.vdw_threshold = vdw_threshold
67
- self.kwargs = kwargs
68
-
69
- def get_config(self) -> dict:
70
- config = {
71
- 'method': self.method,
72
- 'max_iter': self.max_iter,
73
- 'ignore_interfragment_interactions': self.ignore_interfragment_interactions,
74
- 'vdw_threshold': self.vdw_threshold,
75
- }
76
- config.update({
77
- k: v for (k, v) in self.kwargs.items()
78
- })
79
- return config
80
-
81
- def __call__(self, mol: chem.Mol) -> chem.Mol:
82
- return chem.optimize_conformers(
83
- mol,
84
- method=self.method,
85
- max_iter=self.max_iter,
86
- ignore_interfragment_interactions=self.ignore_interfragment_interactions,
87
- vdw_threshold=self.vdw_threshold,
88
- **self.kwargs,
89
- )
90
-
91
-
92
- @keras.saving.register_keras_serializable(package="molcraft")
93
- class ConformerPruner(ConformerProcessor):
94
- def __init__(
95
- self,
96
- keep: int = 1,
97
- threshold: float = 0.0,
98
- energy_force_field: str = 'UFF',
99
- **kwargs,
100
- ) -> None:
101
- self.keep = keep
102
- self.threshold = threshold
103
- self.energy_force_field = energy_force_field
104
- self.kwargs = kwargs
105
-
106
- def get_config(self) -> dict:
107
- config = {
108
- 'keep': self.keep,
109
- 'threshold': self.threshold,
110
- 'energy_force_field': self.energy_force_field,
111
- }
112
- config.update({
113
- k: v for (k, v) in self.kwargs.items()
114
- })
115
- return config
116
-
117
- def __call__(self, mol: chem.Mol) -> chem.Mol:
118
- return chem.prune_conformers(
119
- mol,
120
- keep=self.keep,
121
- threshold=self.threshold,
122
- energy_force_field=self.energy_force_field,
123
- **self.kwargs,
124
- )
125
-
126
-
127
- @keras.saving.register_keras_serializable(package='molcraft')
128
- class ConformerGenerator(ConformerProcessor):
129
-
130
- def __init__(self, steps: list[ConformerProcessor]) -> None:
131
- self.steps = steps
132
-
133
- def get_config(self) -> dict:
134
- return {
135
- "steps": [
136
- keras.saving.serialize_keras_object(step) for step in self.steps
137
- ]
138
- }
139
-
140
- @classmethod
141
- def from_config(cls, config: dict) -> 'ConformerGenerator':
142
- steps = [
143
- keras.saving.deserialize_keras_object(obj)
144
- for obj in config["steps"]
145
- ]
146
- return cls(steps)
147
-
148
- def __call__(self, mol: chem.Mol) -> chem.Mol:
149
- for step in self.steps:
150
- mol = step(mol)
151
- return mol
@@ -1,21 +0,0 @@
1
- molcraft/__init__.py,sha256=uo2ze7WMv3VhP0JcJedXDS9UkeEFydlXgSw4l7Xi8E0,464
2
- molcraft/callbacks.py,sha256=x5HnkZhqcFRrW6xdApt_jZ4X08A-0fxcnFKfdmRKa0c,3571
3
- molcraft/chem.py,sha256=--4AdZV0TCj_cf5i-TRidNJGSFyab1ksUEMjmDi7zaM,21837
4
- molcraft/conformers.py,sha256=K6ZtiSUNDN_fwqGP9JrPcwALLFFvlMlF_XejEJH3Sr4,4205
5
- molcraft/datasets.py,sha256=QKHi9SUBKvJvdkRFmRQNowhrnu35pQqtujuLatOK8bE,4151
6
- molcraft/descriptors.py,sha256=jJpT0XWu3Tx_bxnwk1rENySRkaM8cMDMaDIjG8KKvtg,3097
7
- molcraft/features.py,sha256=GwOecLCNUIuGfbIVzsAJH4LikkzWMKj5IT7zSgGTttU,13846
8
- molcraft/featurizers.py,sha256=8Jmd2yguYmVRyh5wkn6sRzzEENkJ0TqHSlR8qgC4zNY,27131
9
- molcraft/layers.py,sha256=200Y4QLOXDyHw1bnjoSQ6hZ-zD0vpforv-KQGESAZi8,61733
10
- molcraft/losses.py,sha256=qnS2yC5g-O3n_zVea9MR6TNiFraW2yqRgePOisoUP4A,1065
11
- molcraft/models.py,sha256=hKYSV8z65ohRKfPyjjzxZeVjipm064BWeUBGZE0tpyU,21882
12
- molcraft/ops.py,sha256=bQbdFDt9waxVCzF5-dkTB6vlpj9eoSt8I4Qg7ZGXbsU,6178
13
- molcraft/records.py,sha256=MbvYkcCunbAmpy_MWXmQ9WBGi2WvwxFUlwQSPKPvSSk,5534
14
- molcraft/tensors.py,sha256=EOUKx496KUZsjA1zA2ABc7tU_TW3Jv7AXDsug_QsLbA,22407
15
- molcraft/applications/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
- molcraft/applications/proteomics.py,sha256=usZkoYtmTi1BtoP8SigyBNPjxR-nLH1yEsuAdpjvF2M,9009
17
- molcraft-0.1.0a16.dist-info/licenses/LICENSE,sha256=sbVeqlrtZ0V63uYhZGL5dCxUm8rBAOqe2avyA1zIQNk,1074
18
- molcraft-0.1.0a16.dist-info/METADATA,sha256=JL32RxGZY92s39EnhonY4mZbvgGvXjcybtV9nXukn4s,3930
19
- molcraft-0.1.0a16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
- molcraft-0.1.0a16.dist-info/top_level.txt,sha256=dENV6MfOceshM6MQCgJlcN1ojZkiCL9B4F7XyUge3QM,9
21
- molcraft-0.1.0a16.dist-info/RECORD,,