-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvseprw
More file actions
281 lines (228 loc) · 7.72 KB
/
vseprw
File metadata and controls
281 lines (228 loc) · 7.72 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
#!/usr/bin/env bash
# vseprw - VSEPR-Sim Wrapper
# "One command to build/run cleanly, every time"
#
# Usage: ./vseprw <SPEC> <ACTION> [OPTIONS]
# Example: ./vseprw H2O relax --watch
# ./vseprw water.xyz sim --temp 300 --steps 1000
set -euo pipefail
# ============================================================================
# Configuration
# ============================================================================
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="${BUILD_DIR:-$REPO_ROOT/build}"
GENERATOR="${CMAKE_GENERATOR:-Ninja}" # or "Unix Makefiles"
BUILD_TYPE="${BUILD_TYPE:-Release}"
# Tool mapping: DEPRECATED - vseprw now calls single 'vsepr' binary
# The vsepr binary handles all actions internally via grammar:
# vsepr <SPEC> <ACTION> [OPTIONS]
#
# Old approach (removed):
# declare -A TOOL_MAP=(
# ["relax"]="atomistic-relax"
# ["sim"]="atomistic-sim"
# ...
# )
#
# New approach:
VSEPR_BINARY="vsepr"
# Color output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# ============================================================================
# Helper Functions
# ============================================================================
log_info() {
echo -e "${BLUE}[vseprw]${NC} $1"
}
log_success() {
echo -e "${GREEN}[vseprw]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[vseprw]${NC} $1"
}
log_error() {
echo -e "${RED}[vseprw ERROR]${NC} $1" >&2
}
check_toolchain() {
log_info "Checking toolchain..."
if ! command -v cmake &> /dev/null; then
log_error "CMake not found. Install CMake 3.15+"
exit 1
fi
local cmake_version=$(cmake --version | head -n1 | awk '{print $3}')
log_info "CMake: $cmake_version"
if [[ "$GENERATOR" == "Ninja" ]] && ! command -v ninja &> /dev/null; then
log_warn "Ninja not found, falling back to Make"
GENERATOR="Unix Makefiles"
fi
if command -v g++ &> /dev/null; then
local gxx_version=$(g++ --version | head -n1)
log_info "Compiler: $gxx_version"
elif command -v clang++ &> /dev/null; then
local clang_version=$(clang++ --version | head -n1)
log_info "Compiler: $clang_version"
else
log_error "No C++ compiler found (g++ or clang++)"
exit 1
fi
log_success "Toolchain ready"
}
configure_project() {
if [[ -f "$BUILD_DIR/CMakeCache.txt" ]]; then
log_info "Build directory exists: $BUILD_DIR"
return 0
fi
log_info "Configuring project..."
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cmake -G "$GENERATOR" \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DBUILD_TESTS=ON \
-DBUILD_APPS=ON \
-DBUILD_VIS=ON \
"$REPO_ROOT"
cd "$REPO_ROOT"
log_success "Configuration complete"
}
build_project() {
if [[ ! -f "$BUILD_DIR/CMakeCache.txt" ]]; then
log_error "Build directory not configured. Run configure first."
exit 1
fi
log_info "Building project ($BUILD_TYPE)..."
cd "$BUILD_DIR"
cmake --build . --config "$BUILD_TYPE" -j$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
cd "$REPO_ROOT"
log_success "Build complete"
}
check_build_freshness() {
# Simple heuristic: if any source file is newer than the binary, rebuild
local binary="$1"
if [[ ! -f "$binary" ]]; then
return 1 # Needs build
fi
# Check if any .cpp or .hpp in meso/ or apps/ is newer
local needs_rebuild=0
while IFS= read -r -d '' src_file; do
if [[ "$src_file" -nt "$binary" ]]; then
needs_rebuild=1
break
fi
done < <(find "$REPO_ROOT/src" "$REPO_ROOT/apps" -name "*.cpp" -o -name "*.hpp" -print0 2>/dev/null)
return $needs_rebuild
}
show_usage() {
cat << 'EOF'
vseprw - VSEPR-Sim Wrapper
===========================
One command to build/run cleanly, every time.
USAGE:
./vseprw <SPEC> <ACTION> [OPTIONS]
SPEC:
- Molecule formula (H2O, CH4, CO2)
- XYZ file path (water.xyz, crystal.xyz)
- System name (NaCl, diamond)
ACTION:
relax Energy minimization (FIRE algorithm)
sim Molecular dynamics simulation
discover Reaction discovery analysis
align Kabsch alignment
build Interactive molecule builder
crystal Crystallographic viewer
qa Run QA golden tests
OPTIONS:
Passed directly to the underlying tool.
Use --help with each action for details.
EXAMPLES:
./vseprw H2O relax
./vseprw water.xyz sim --temp 300 --steps 1000
./vseprw ethanol.xyz discover --threshold 2.5
./vseprw NaCl crystal --pbc
ENVIRONMENT:
BUILD_DIR Build directory (default: ./build)
CMAKE_GENERATOR CMake generator (default: Ninja)
BUILD_TYPE Build type (default: Release)
MODES:
--configure-only Configure CMake without building
--build-only Build project without running tool
--clean Clean build directory
--help Show this message
EOF
}
# ============================================================================
# Main Logic
# ============================================================================
main() {
# Handle special modes
if [[ $# -eq 0 ]] || [[ "${1:-}" == "--help" ]] || [[ "${1:-}" == "-h" ]]; then
show_usage
exit 0
fi
if [[ "${1:-}" == "--configure-only" ]]; then
check_toolchain
configure_project
exit 0
fi
if [[ "${1:-}" == "--build-only" ]]; then
check_toolchain
configure_project
build_project
exit 0
fi
if [[ "${1:-}" == "--clean" ]]; then
log_info "Cleaning build directory: $BUILD_DIR"
rm -rf "$BUILD_DIR"
log_success "Clean complete"
exit 0
fi
# Parse SPEC and ACTION
if [[ $# -lt 2 ]]; then
log_error "Missing SPEC or ACTION"
echo ""
show_usage
exit 1
fi
local spec="$1"
local action="$2"
shift 2
local options=("$@")
# All actions now go through single vsepr binary
local binary="$BUILD_DIR/$VSEPR_BINARY"
# Ensure toolchain
check_toolchain
# Configure if needed
if [[ ! -f "$BUILD_DIR/CMakeCache.txt" ]]; then
log_info "First run: configuring project"
configure_project
fi
# Build if needed
if ! check_build_freshness "$binary"; then
log_info "Binary stale or missing, rebuilding..."
build_project
else
log_info "Binary up-to-date"
fi
# Verify binary exists
if [[ ! -f "$binary" ]]; then
log_error "vsepr binary not found after build"
log_error "Expected: $binary"
exit 1
fi
# Show execution summary
log_info "╔═══════════════════════════════════════════════════════"
log_info "║ SPEC: $spec"
log_info "║ ACTION: $action"
log_info "║ BINARY: $VSEPR_BINARY"
log_info "║ BUILD: $BUILD_DIR"
log_info "║ TYPE: $BUILD_TYPE"
log_info "╚═══════════════════════════════════════════════════════"
echo ""
# Execute: vsepr SPEC ACTION OPTIONS
cd "$REPO_ROOT"
"$binary" "$spec" "$action" "${options[@]}"
}
main "$@"