File size: 2,238 Bytes
9fc3c5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""

Test script for the new molecule validator

"""
from modules.molecule_validator import process_molecule_input, get_similar_molecules

print("=" * 60)
print("TESTING NEW MOLECULE VALIDATOR")
print("=" * 60)

# Test cases covering all input formats
test_cases = [
    # Common names
    ("water", True),
    ("hydrogen", True),
    ("methane", True),
    ("iron", True),
    ("platinum", True),

    # Molecular formulas
    ("H2O", True),
    ("CO2", True),
    ("H2", True),
    ("O2", True),
    ("NH3", True),

    # SMILES strings
    ("O", True),  # Water (3 atoms: O + 2H)
    ("C", True),  # Methane (5 atoms: C + 4H)
    ("[Fe]", True),  # Iron (1 atom)
    ("C=C", True),  # Ethylene (6 atoms: 2C + 4H)

    # Invalid inputs
    ("CC", False),  # Ethane (8 atoms: 2C + 6H - exceeds limit)
    ("CCCCCCCCCC", False),  # Too many atoms
    ("XYZ123", False),  # Nonsense
    ("benzene", False),  # Too many atoms (12 total)
]

print("\nRunning validation tests...\n")

for i, (input_str, should_pass) in enumerate(test_cases, 1):
    result = process_molecule_input(input_str, max_atoms=6)
    status = "[PASS]" if result["valid"] == should_pass else "[FAIL]"

    print(f"{status} Test {i}: '{input_str}'")
    print(f"   Expected: {'VALID' if should_pass else 'INVALID'}")
    print(f"   Got: {'VALID' if result['valid'] else 'INVALID'}")

    if result["valid"]:
        print(f"   Formula: {result['formula']}")
        print(f"   SMILES: {result['smiles']}")
        print(f"   Atoms: {result['atom_count']} (Heavy: {result['heavy_atom_count']})")
        print(f"   Weight: {result['mol_weight']} g/mol")
        print(f"   Elements: {', '.join(result['elements'])}")
    else:
        print(f"   Error: {result['error']}")
    print()

print("=" * 60)
print("Testing suggestion system...")
print("=" * 60)

# Test suggestions for failed inputs
test_queries = ["wat", "meth", "iro"]
for query in test_queries:
    suggestions = get_similar_molecules(query, limit=3)
    print(f"\nQuery: '{query}'")
    print(f"Suggestions: {', '.join(suggestions) if suggestions else 'None'}")

print("\n" + "=" * 60)
print("VALIDATOR TEST COMPLETE")
print("=" * 60)