-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_cli.py
More file actions
89 lines (67 loc) · 3.2 KB
/
main_cli.py
File metadata and controls
89 lines (67 loc) · 3.2 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
"""Interactive CLI for the ChemTrace chemistry scouting agent."""
import json
import os
import sys
from decision_engine import evaluate_chemtrace_output
# Add project root for src imports when run from repository root.
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".")))
import pubchempy as pcp
from src.agents.chemistry_agent import ChemistryAgent
def main() -> None:
"""Run an interactive terminal loop for molecule scouting."""
agent = ChemistryAgent()
print("========================================")
print("ChemTrace: Autonomous Chemistry Scout")
print("========================================")
print("Type 'exit' or 'quit' to stop.")
while True:
user_input = input("\nEnter Molecule SMILES > ").strip()
if user_input.lower() in ["exit", "quit"]:
print("Shutting down scout...")
break
if not user_input:
continue
if not any(char in user_input for char in ["=", "(", ")", "#", "[", "]"]):
print(f"Attempting to resolve name '{user_input}' to SMILES...")
try:
results = pcp.get_compounds(user_input, "name")
if results and results[0].isomeric_smiles:
user_input = results[0].isomeric_smiles
print(f"Resolved to: {user_input}")
else:
print("Could not resolve name to SMILES. Proceeding with raw input.")
except Exception as exc:
print(f"Name resolution failed: {exc}. Proceeding with raw input.")
print(f"Scouting {user_input}...")
try:
result = agent.scout_synthesis(user_input)
if result.get("status") == "error":
print("Error(s):")
for err in result.get("errors", []):
print(f"- {err}")
continue
print("\nDATA RETRIEVED:")
print(json.dumps(result, indent=2))
ranked_routes = evaluate_chemtrace_output(result)
print("\n========================================")
print("DECISION ENGINE OUTPUT")
print("========================================")
print(json.dumps(ranked_routes, indent=2))
if ranked_routes:
best_route = ranked_routes[0]
print("\n========================================")
print("BEST ROUTE SUMMARY")
print("========================================")
print(f"Route ID: {best_route['route_id']}")
print(f"Score: {best_route['score']}")
print(f"Status: {best_route['status']}")
print(f"Estimated Cost per Gram: {best_route['cost_per_gram']}")
print(f"Supply Chain Risk: {best_route['supply_chain_risk']}")
print(f"Regulatory Risk: {best_route['regulatory_risk']}")
print(f"Step Count: {best_route['step_count']}")
print(f"Yield Estimate: {best_route['yield_estimate']}")
print(f"Reason: {best_route['decision_reason']}")
except Exception as exc:
print(f"Critical failure: {exc}")
if __name__ == "__main__":
main()