-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_OHMind_full.sh
More file actions
136 lines (113 loc) · 4.42 KB
/
Copy pathstart_OHMind_full.sh
File metadata and controls
136 lines (113 loc) · 4.42 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
#!/usr/bin/env bash
# Full OHMind Launcher - Starts MCP servers and CLI
# This script starts all MCP servers and then launches the CLI.
#
# Usage:
# chmod +x start_OHMind_full.sh
# ./start_OHMind_full.sh # Run as TUI
# ./start_OHMind_full.sh --debug # Enable CLI debug mode
# ./start_OHMind_full.sh deploy # Serve as web app on default port 8000
# ./start_OHMind_full.sh deploy --port 9000 # Serve on custom port
# ./start_OHMind_full.sh deploy --host 0.0.0.0 --port 8080 # Custom host and port
#
# Environment variables you can override:
# PYTHON - python executable to use
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG_DIR="${ROOT_DIR}/OHMind_logs"
mkdir -p "${LOG_DIR}"
export PYTHON_BIN="${PYTHON:-/home/polyai/anaconda3/envs/OHMind_copy/bin/python}"
export MCP_CHEM_PORT="${MCP_CHEM_PORT:-8101}"
export MCP_HEMDESIGN_PORT="${MCP_HEMDESIGN_PORT:-8102}"
export MCP_ORCA_PORT="${MCP_ORCA_PORT:-8103}"
export MCP_MULTIWFN_PORT="${MCP_MULTIWFN_PORT:-8104}"
export MCP_GROMACS_PORT="${MCP_GROMACS_PORT:-8105}"
# Load environment variables
GLOBAL_ENV_FILE="${ROOT_DIR}/.env"
if [ -f "$GLOBAL_ENV_FILE" ]; then
echo "[OHMind] Loading environment from ${GLOBAL_ENV_FILE}"
set -a
. "$GLOBAL_ENV_FILE"
set +a
fi
ENV_FILE="${ROOT_DIR}/OHMind_ui/.env"
if [ -f "$ENV_FILE" ]; then
echo "[OHMind] Loading environment from ${ENV_FILE}"
set -a
. "$ENV_FILE"
set +a
fi
export PYTHONPATH="${PYTHONPATH:-${ROOT_DIR}}"
export OHMind_workspace="${OHMind_workspace:-/media/polyai/8T/MyResearch/CationDesign/OHMind_workspace}"
export HEM_SAVE_PATH="${OHMind_workspace}"
export QM_WORK_DIR="${OHMind_workspace}"
export MD_WORK_DIR="${OHMind_workspace}"
export MULTIWFN_WORK_DIR="${OHMind_workspace}"
export CHEM_WORK_DIR="${OHMind_workspace}"
export OHMind_ORCA="${OHMind_ORCA:-/home/polyai/ORCA610/orca-6.1.0-f.0_linux_x86-64/bin/orca}"
export OHMind_MPI="${OHMind_MPI:-/usr/local/bin}"
export MULTIWFN_PATH="${MULTIWFN_PATH:-/home/polyai/Multiwfn38/Multiwfn}"
mkdir -p "${OHMind_workspace}"
cd "${ROOT_DIR}"
echo "[OHMind] ================================================"
echo "[OHMind] Starting OHMind Full System (MCP + CLI)"
echo "[OHMind] ================================================"
# Track PIDs for cleanup
PIDS=()
cleanup() {
echo ""
echo "[OHMind] Cleaning up..."
for pid in "${PIDS[@]}"; do
if kill -0 "$pid" 2>/dev/null; then
echo "[OHMind] Stopping process $pid"
kill "$pid" 2>/dev/null || true
fi
done
echo "[OHMind] Cleanup complete"
}
trap cleanup EXIT INT TERM
# Start MCP servers
start_mcp_if_needed() {
local port=$1
local name=$2
local module=$3
local logname=$4
if lsof -i ":${port}" >/dev/null 2>&1; then
echo "[OHMind] ✓ ${name} already running on port ${port}"
else
echo "[OHMind] Starting ${name} on port ${port}..."
"${PYTHON_BIN}" -m "${module}" --transport streamable-http --host 0.0.0.0 --port "${port}" > "${LOG_DIR}/${logname}.log" 2>&1 &
PIDS+=($!)
sleep 2 # Give each server time to start
# Verify it started
if lsof -i ":${port}" >/dev/null 2>&1; then
echo "[OHMind] ✓ ${name} started successfully"
else
echo "[OHMind] ✗ ${name} failed to start - check ${LOG_DIR}/${logname}.log"
fi
fi
}
echo ""
echo "[OHMind] Starting MCP servers..."
start_mcp_if_needed "${MCP_CHEM_PORT}" "Chem MCP" "OHMind_agent.MCP.Chem.server" "chem_mcp"
start_mcp_if_needed "${MCP_HEMDESIGN_PORT}" "HEMDesign MCP" "OHMind_agent.MCP.HEMDesign.server" "hem_mcp"
start_mcp_if_needed "${MCP_ORCA_PORT}" "ORCA MCP" "OHMind_agent.MCP.ORCA.server" "orca_mcp"
start_mcp_if_needed "${MCP_MULTIWFN_PORT}" "Multiwfn MCP" "OHMind_agent.MCP.Multiwfn.server" "multiwfn_mcp"
start_mcp_if_needed "${MCP_GROMACS_PORT}" "GROMACS MCP" "OHMind_agent.MCP.GROMACS.server" "gromacs_mcp"
# Wait for all servers to be fully initialized
echo ""
echo "[OHMind] Waiting for MCP servers to fully initialize..."
sleep 5
echo ""
# Check if 'deploy' is in the arguments
if [[ " $* " =~ " deploy " ]]; then
echo "[OHMind] Starting Web Server (deploy mode)..."
echo ""
else
echo "[OHMind] Starting CLI..."
echo ""
fi
# Run CLI (this will block until exit)
# Use the new Textual-based app instead of the old rich-based cli
# Pass all arguments to support both TUI and deploy modes
"${PYTHON_BIN}" -m OHMind_cli "$@"