-
Notifications
You must be signed in to change notification settings - Fork 30
/
install_tutorial.sh
executable file
·327 lines (290 loc) · 8.54 KB
/
install_tutorial.sh
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/bin/bash
set -e
url=www.student.dtu.dk/~nicpa/sisl/workshop/23
indir=$HOME/TBT-TS-sisl-workshop
# We install miniconda in the $indir
# Hence we don't need an enviroment, we just have it here
# as a place-holder.
env_name="2023-workshop-ts-sisl"
if command -v wget &> /dev/null ; then
function download_file {
local url=$1
local out=$2
shift 2
wget -O $out $url
local retval=$?
if [ $retval -ne 0 ]; then
echo "Failed to download: $url to $out"
fi
return $retval
}
elif command -v curl &> /dev/null ; then
function download_file {
local url=$1
local out=$2
shift 2
curl -k -o $out -LO $url
local retval=$?
if [ $retval -ne 0 ]; then
echo "Failed to download: $url to $out"
fi
return $retval
}
else
echo "Cannot find either wget or curl command, please install one of them on your machine"
exit 1
fi
function _help {
echo "This script may be used to install the dependencies for the"
echo "tutorial such as Python, numpy, scipy, matplotlib, jupyter and sisl and hubbard."
echo ""
echo "This script is a two-step script. Please read below."
echo ""
echo "Running this script in installation mode will download and install conda"
echo "conda provides both Siesta executables as well as the sisl and dependency packages"
echo "so once installed all required infrastructure is available."
echo "It does, however, require a disk space of approximately >4GB"
echo ""
echo "To use the conda framework, run this script in installation mode:"
echo ""
echo " $0 install"
echo ""
echo "If you can install Siesta (master version) and sisl 0.14.3 and the rest of the dependencies"
echo "manually then you won't be needing the above installation procedure."
echo "However, we cannot assist installing the packages manually."
echo ""
echo "Once the above step is fulfilled you should run the download part"
echo "of the script. It will download the required files for the tutorial:"
echo ""
echo " $0 download"
echo ""
}
if [ $# -eq 0 ]; then
_help
exit 1
fi
# First we get the current directory
cwd=$(pwd)
# Figure out if we are dealing with UNIX or MacOS
os=$(uname -s)
arch=$(uname -m)
case "${os}" in
Linux|Darwin)
;;
*)
echo "Are you using MingGW or FreeBSD? Or a (${os})?"
echo "Either way this installation script does not work for your distribution..."
exit 1
;;
esac
action=install
case $1 in
install)
# do nothing, we use the OS to determine stuff
action=install
;;
update)
# Update this script
# Try and update
base=$(basename $0)
cp $cwd/$0 $cwd/old_$base
download_file $url/install_tutorial.sh $cwd/new_$base
if [ $? -eq 0 ]; then
mv $cwd/new_$base $cwd/$base
chmod u+x $cwd/$base
echo ""
echo "Successfully updated script..."
rm $cwd/old_$base
fi
exit 0
;;
download)
action=download
;;
fix)
action=fix
;;
*)
echo "###########################################"
echo "# Unknown argument: $1"
echo "#"
echo "# Should be either 'install', 'update' or 'download'"
echo "#"
echo "###########################################"
echo ""
_help
exit 1
;;
esac
function fix_sisl {
# TODO this only fixes the 0.14.3 version, if a later version in installed,
# then there is no need.
sed -i -s -e 's:geometry.set_boundary_condition:geometry.lattice.set_boundary_condition:' $indir/miniconda3/lib/python3.*/site-packages/sisl_toolbox/transiesta/poisson/fftpoisson_fix.py
}
function conda_install {
local exe=$1 ; shift
if [ ! -e $indir/miniconda3/bin/activate ]; then
if [ ! -e $exe ]; then
download_file https://repo.anaconda.com/miniconda/$exe $exe
[ $? -ne 0 ] && exit 1
fi
sh ./$exe -b -s -f -p $indir/miniconda3
source $indir/miniconda3/bin/activate
conda update -y -n base conda
else
source $indir/miniconda3/bin/activate
fi
if [[ ${arch} == "arm64" ]]; then
# see https://github.com/conda-forge/miniforge/issues/165#issuecomment-860233092
# This should use rosetta under the hood, if not
# then open a terminal by emulating x86-64
conda config --env --set subdir osx-64
fi
local -a packages=
packages=(
"python<3.12"
"siesta=5.0.0rc1=*openmpi*"
"sisl=0.14.3"
"netCDF4"
"jupyter"
"pyamg"
"pathos"
"matplotlib"
"plotly"
"scikit-image"
"py3dmol"
)
# install everything
conda install -y -c conda-forge/label/siesta_rc -c conda-forge ${packages[@]}
[ $? -ne 0 ] && { echo "failed" ; exit 1; }
fix_sisl
# remove unused tarballs (no need for them to be around)
conda clean -t -y
{
echo "#!/bin/bash"
echo "source $indir/miniconda3/bin/activate"
echo "export OMPI_MCA_btl='vader,self'"
} > $indir/setup.sh
source $indir/setup.sh
# hubbard
local v=0.4.1
download_file https://github.com/dipc-cc/hubbard/archive/refs/tags/v$v.tar.gz hubbard-$v.tar.gz
[ $? -ne 0 ] && exit 1
tar xfz hubbard-$v.tar.gz
cd hubbard-$v
python -m pip install .
[ $? -ne 0 ] && exit 1
cd ../
rm -rf hubbard-$v hubbard-$v.tar.gz
echo ""
echo "Before you can run exercises etc. you should execute the following:"
echo ""
echo " source $indir/setup.sh"
echo ""
}
# Function for installation on Linux
function linux_install {
conda_install Miniconda3-latest-Linux-${arch}.sh
}
function macos_install {
if [[ ${arch} == "arm64" ]]; then
export CONDA_SUBDIR=osx-64
fi
conda_install Miniconda3-latest-MacOSX-${arch}.sh
}
function install_warning {
echo "RUNNING THIS SCRIPT IS AT YOUR OWN RISK!!!"
echo "THIS SCRIPT IS MADE FOR HELPFUL PURPOSE, BUT YOU ARE"
echo "RESPONSIBLE FOR ANY ERRORS/DATALOSSES THIS SCRIPT MAY INFER."
echo "IF YOU DO NOT WANT TO RUN THIS SCRIPT PRESS:"
echo ""
echo " CTRL+^C"
echo ""
echo "Please ensure you have more than 5 GB of disk space available!"
echo ""
sleep 3
}
# Now create a common folder in the top-home directory
function download_warning {
echo ""
echo "This script will create a folder in your $HOME directory:"
echo " $HOME/TBT-TS-sisl-workshop"
echo "where all the tutorials and executable files will be downloaded."
echo ""
}
function install_test_sisl {
echo ""
echo " Will try and run sisl and hubbard"
local cmd="import sisl ; print(sisl.__file__, sisl.__version__)"
echo " import sisl ; print(sisl.__file__, sisl.__version__)"
cmd="$cmd ; import hubbard ; print(hubbard.__file__)"
echo " import sisl.viz"
cmd="$cmd ; import sisl.viz"
python -c "$cmd"
if [ $? -ne 0 ]; then
echo "Failed running sisl, please mail the organizer with the error message (unless some of the installations failed)"
fi
}
# create installation directory
mkdir -p $indir
pushd $indir
if [ $action == fix ]; then
fix_sisl
exit 0
elif [ $action == install ]; then
# os will be download
download_warning
install_warning
case $os in
Linux)
linux_install
;;
Darwin)
macos_install
;;
esac
install_test_sisl
exit 0
else
download_warning
fi
# Download latest tutorial files
mkdir -p tarball
for file in sisl-TBT-TS.tar.gz hubbard-tutorials.tar.gz xabier-tutorials.tar.gz DFT-TB.tar.gz
do
if [ -e tarball/$file ]; then
rm tarball/$file
fi
download_file $url/$file tarball/$file
[ $? -ne 0 ] && exit 1
done
{
echo "Please be careful about extracting these tarballs."
echo "If you extract them on top of tutorials you have already"
echo "completed, you will overwrite any progress made!"
echo "Please untar in a fresh directory and move the files you need."
} > tarball/README
mkdir -p presentations
for file in talk_1.pdf talk_3.pdf talk_4.pdf RSSE.pdf
do
if [ -e presentations/$file ]; then
rm presentations/$file
fi
download_file $url/$file presentations/$file
[ $? -ne 0 ] && exit 1
done
echo ""
echo "In folders"
echo " $indir"
echo " $indir/tarball"
echo " $indir/presentations"
echo "you will find everything needed for the tutorial."
echo "If you are using the conda installation provided by this script"
echo "please always start your sessions by executing:"
echo ""
echo " source $indir/setup.sh"
echo ""
echo "which will correctly setup the environment for you."
echo "Run (after you have restarted your shell):"
echo " which tbtrans"
echo "and check it returns $indir/miniconda3/bin/tbtrans"