-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_fresh_install.py
More file actions
executable file
·289 lines (232 loc) · 8.66 KB
/
test_fresh_install.py
File metadata and controls
executable file
·289 lines (232 loc) · 8.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/usr/bin/env python3
"""
Test script for MolForge fresh installation.
This script tests basic functionality of MolForge in a fresh environment.
Run this after installing MolForge to verify the installation.
Usage:
python test_fresh_install.py
"""
import sys
import pandas as pd
from pathlib import Path
def test_imports():
"""Test that all core modules can be imported."""
print("=" * 70)
print("Testing imports...")
print("=" * 70)
try:
from molforge import (
MolForge,
ForgeParams,
ConstructPipe,
ChEMBLSourceParams,
ChEMBLCuratorParams,
CurateMolParams,
TokenizeDataParams,
CurateDistributionParams,
GenerateConfsParams,
)
print("✓ All core imports successful")
return True
except Exception as e:
print(f"✗ Import failed: {e}")
return False
def test_basic_curation():
"""Test basic molecule curation functionality."""
print("\n" + "=" * 70)
print("Testing basic molecule curation...")
print("=" * 70)
try:
from molforge import MolForge, ForgeParams, CurateMolParams
import tempfile
# Create test data
test_smiles = [
'CCO', # Ethanol
'c1ccccc1', # Benzene
'CC(C)O', # Isopropanol
'CCN(CC)CC', # Triethylamine
]
test_df = pd.DataFrame({'SMILES': test_smiles})
# Create temporary directory for output
with tempfile.TemporaryDirectory() as tmpdir:
# Configure pipeline
params = ForgeParams(
steps=['curate'],
output_root=tmpdir,
write_checkpoints=False,
curate_params=CurateMolParams(
SMILES_column='SMILES',
mol_steps=['sanitize', 'neutralize'],
smiles_steps=['canonical'],
dropna=True
)
)
# Run pipeline
forge = MolForge(params)
result = forge.forge(test_df, input_id="test")
# Verify results
assert result is not None, "Result is None"
assert isinstance(result, pd.DataFrame), "Result is not a DataFrame"
assert len(result) > 0, "Result is empty"
assert 'curated_smiles' in result.columns, "Missing curated_smiles column"
print(f"✓ Curated {len(result)} molecules successfully")
print(f" Columns: {', '.join(result.columns)}")
return True
except Exception as e:
print(f"✗ Curation test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_tokenization():
"""Test SMILES tokenization."""
print("\n" + "=" * 70)
print("Testing SMILES tokenization...")
print("=" * 70)
try:
from molforge import MolForge, ForgeParams, CurateMolParams, TokenizeDataParams
import tempfile
test_smiles = ['CCO', 'c1ccccc1', 'CC(C)O']
test_df = pd.DataFrame({'SMILES': test_smiles})
with tempfile.TemporaryDirectory() as tmpdir:
params = ForgeParams(
steps=['curate', 'tokens'],
output_root=tmpdir,
write_checkpoints=False,
curate_params=CurateMolParams(
SMILES_column='SMILES',
mol_steps=['sanitize'],
smiles_steps=['canonical'],
dropna=True
),
tokens_params=TokenizeDataParams(
SMILES_column='curated_smiles',
dynamically_update_vocab=True
)
)
forge = MolForge(params)
result = forge.forge(test_df, input_id="test")
assert 'tokens' in result.columns, "Missing tokens column"
assert 'seqlen' in result.columns, "Missing seqlen column"
print(f"✓ Tokenized {len(result)} molecules successfully")
print(f" Example tokens: {result['tokens'].iloc[0][:50]}...")
return True
except Exception as e:
print(f"✗ Tokenization test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_conformer_generation():
"""Test 3D conformer generation."""
print("\n" + "=" * 70)
print("Testing conformer generation...")
print("=" * 70)
try:
from molforge import MolForge, ForgeParams, CurateMolParams, GenerateConfsParams
import tempfile
# Use simple molecules for fast testing
test_smiles = ['CCO', 'CC(C)O']
test_df = pd.DataFrame({'SMILES': test_smiles})
with tempfile.TemporaryDirectory() as tmpdir:
params = ForgeParams(
steps=['curate', 'confs'],
output_root=tmpdir,
write_checkpoints=False,
curate_params=CurateMolParams(
SMILES_column='SMILES',
mol_steps=['sanitize'],
smiles_steps=['canonical'],
dropna=True
),
confs_params=GenerateConfsParams(
backend='rdkit',
SMILES_column='curated_smiles',
max_confs=5, # Small number for fast testing
rms_threshold=0.5,
use_uff=True,
max_iterations=100
)
)
forge = MolForge(params)
result = forge.forge(test_df, input_id="test")
assert 'conformer_success' in result.columns, "Missing conformer_success column"
assert 'n_conformers' in result.columns, "Missing n_conformers column"
successful = result['conformer_success'].sum()
print(f"✓ Generated conformers for {successful}/{len(result)} molecules")
print(f" Total conformers: {result['n_conformers'].sum()}")
return True
except Exception as e:
print(f"✗ Conformer generation test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_construct_pipe():
"""Test ConstructPipe direct usage."""
print("\n" + "=" * 70)
print("Testing ConstructPipe...")
print("=" * 70)
try:
from molforge import ConstructPipe, ForgeParams, CurateMolParams
import tempfile
test_smiles = ['CCO', 'c1ccccc1']
test_df = pd.DataFrame({'SMILES': test_smiles})
with tempfile.TemporaryDirectory() as tmpdir:
params = ForgeParams(
steps=['curate'],
output_root=tmpdir,
write_checkpoints=False,
curate_params=CurateMolParams(
SMILES_column='SMILES',
mol_steps=['sanitize'],
smiles_steps=['canonical'],
dropna=True
)
)
pipeline = ConstructPipe(params)
result = pipeline(test_df, input_id="test_pipe")
assert result is not None, "Pipeline result is None"
assert len(result) > 0, "Pipeline result is empty"
print(f"✓ ConstructPipe processed {len(result)} molecules successfully")
return True
except Exception as e:
print(f"✗ ConstructPipe test failed: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""Run all tests."""
print("\n" + "=" * 70)
print("MolForge Fresh Installation Test")
print("=" * 70)
tests = [
("Imports", test_imports),
("Basic Curation", test_basic_curation),
("Tokenization", test_tokenization),
("Conformer Generation", test_conformer_generation),
("ConstructPipe", test_construct_pipe),
]
results = []
for name, test_func in tests:
try:
result = test_func()
results.append((name, result))
except Exception as e:
print(f"\n✗ Test '{name}' crashed: {e}")
results.append((name, False))
# Summary
print("\n" + "=" * 70)
print("Test Summary")
print("=" * 70)
passed = sum(1 for _, result in results if result)
total = len(results)
for name, result in results:
status = "✓ PASS" if result else "✗ FAIL"
print(f"{status}: {name}")
print(f"\nTotal: {passed}/{total} tests passed")
if passed == total:
print("\n🎉 All tests passed! MolForge is ready to use.")
return 0
else:
print(f"\n⚠️ {total - passed} test(s) failed. Please check the output above.")
return 1
if __name__ == "__main__":
sys.exit(main())