-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpost-init.sh
More file actions
114 lines (97 loc) · 4.37 KB
/
post-init.sh
File metadata and controls
114 lines (97 loc) · 4.37 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
#!/bin/bash
# =============================================================================
# AiiDA-RenkuLab Session Initialization Script
# Consolidated setup and initialization for Materials Cloud Archive exploration
# =============================================================================
set -e
echo "===== AiiDA-RenkuLab Session Setup ====="
project_dir="$(pwd)/work/renku2-aiida-integration"
script_dir="${project_dir}/.scripts"
archive_dir="${project_dir}/data/aiida"
# Export AIIDA_PATH environment variable
export AIIDA_PATH=$HOME
# Make scripts executable
echo "Making scripts executable..."
chmod +x "${script_dir}/fetch_mca_metadata.py" 2>/dev/null || true
chmod +x "${script_dir}/process_notebook.py" 2>/dev/null || true
# Create necessary directories
echo "Creating directories..."
mkdir -p "$archive_dir"
mkdir -p "/tmp/renku_sessions" 2>/dev/null || true
# =============================================================================
# METADATA PROCESSING
# =============================================================================
if [ -n "$archive_url" ]; then
echo ""
echo "Archive URL detected: $archive_url"
# Normalize URL by removing /content suffix if present
normalized_url="$archive_url"
if [[ "$normalized_url" == *"/content" ]]; then
normalized_url="${normalized_url%/content}"
echo "Normalized URL (removed /content): $normalized_url"
fi
# Verify URL format using normalized URL
if [[ "$normalized_url" != *"/records/"* ]] || [[ "$normalized_url" != *"/files/"* ]] || [[ "$normalized_url" != *".aiida"* ]]; then
echo "Error: URL does not match expected Materials Cloud Archive format"
echo "Expected: https://archive.materialscloud.org/records/{record_id}/files/{filename.aiida}"
echo ""
echo "Continuing with manual setup mode..."
unset archive_url
else
# Extract basic info for display using normalized URL
if [[ "$normalized_url" =~ /files/([^/?]+) ]]; then
archive_filename="${BASH_REMATCH[1]}"
archive_filename=$(python3 -c "import urllib.parse; print(urllib.parse.unquote('$archive_filename'))")
echo "Archive filename: $archive_filename"
fi
if [[ "$normalized_url" =~ /records/([^/]+)/ ]]; then
record_id="${BASH_REMATCH[1]}"
echo "Record ID: $record_id"
fi
# Fetch metadata from Materials Cloud Archive
echo "Fetching dataset metadata from Materials Cloud Archive..."
if python3 "${script_dir}/fetch_mca_metadata.py"; then
echo "✓ Metadata fetched successfully"
else
echo "⚠ Warning: Failed to fetch metadata, continuing with basic info"
# Set basic environment variables from URL parsing
export MCA_ARCHIVE_FILENAME="$archive_filename"
export MCA_AIIDA_PROFILE=$(python3 -c "import os; print(os.path.splitext('$archive_filename')[0])" 2>/dev/null || echo "aiida-renku")
fi
fi
else
echo "No archive URL provided - setting up for manual archive import"
fi
# =============================================================================
# NOTEBOOK PROCESSING
# =============================================================================
echo ""
echo "Processing notebook template..."
if python3 "${script_dir}/process_notebook.py"; then
echo "✓ Notebook processed successfully"
else
echo "Warning: Failed to process notebook template"
# Copy template as fallback
if [ -f "${project_dir}/notebooks/.explore_template.ipynb" ] && [ ! -f "${project_dir}/notebooks/explore.ipynb" ]; then
cp "${project_dir}/notebooks/.explore_template.ipynb" "${project_dir}/notebooks/explore.ipynb"
echo "✓ Used template notebook as fallback"
fi
fi
echo ""
echo "===== Setup Complete ====="
echo ""
echo "Ready to explore! Open notebooks/explore.ipynb to get started."
echo ""
if [ -n "$archive_url" ]; then
echo "Next steps:"
echo " 1. Open the notebook to see dataset information"
echo " 2. Run the archive download cell to fetch the data"
echo " 3. Run the AiiDA setup cell to create the profile"
echo " 4. Start exploring your data!"
else
echo "Next steps:"
echo " 1. Open the notebook for manual setup instructions"
echo " 2. Download or upload your .aiida archive"
echo " 3. Follow the notebook instructions to import"
fi
echo ""