changed 2 years ago
Linked with GitHub

MD2-lab Conda setup

Setup

  1. You need to have miniconda3 or Anaconda setup on the computer.

To use Conda on Rackham
# Adapt for the current project
$ UPPMAX_proj=uppmax2022-2-26

$ export CONDA_ENVS_PATH=/proj/$UPPMAX_proj/nobackup/common/CONDA_ENVS
$ mkdir -p $CONDA_ENVS_PATH
$ module load conda
$ source conda_init.sh
(base) _

Providing, that the file access is set correct, everyone with the access to this $CONDA_ENVS_PATH can load any of the installed environments

(base) conda activate MD2-lab

  1. Create conda environment (MD2-lab.yaml).
(base) conda env create -f https://github.com/pmitev/Teoroo-singularity/raw/master/MD2-lab/MD2-lab.yaml
  1. Activate the environment
(base) conda activate MD2-lab
(MD2-lab) export PYTHONNOUSERSITE=True
  1. Check if the tools are installed and run.
(MD2-lab) ase info
platform                 Linux-5.15.0-47-generic-x86_64-with-glibc2.35
python-3.10.6            /home/user/miniconda3/envs/MD2-lab/bin/python3.10
ase-3.22.1               /home/user/miniconda3/envs/MD2-lab/lib/python3.10/site-packages/ase
numpy-1.23.3             /home/user/miniconda3/envs/MD2-lab/lib/python3.10/site-packages/numpy
scipy-1.9.1              /home/user/miniconda3/envs/MD2-lab/lib/python3.10/site-packages/scipy
matplotlib-3.6.0         /home/user/miniconda3/envs/MD2-lab/lib/python3.10/site-packages/matplotlib
spglib                   not installed
ase_ext                  not installed
flask-2.2.2              /home/user/miniconda3/envs/MD2-lab/lib/python3.10/site-packages/flask
psycopg2                 not installed
pyamg                    not installed
  1. To safely run the codes, run them from the python interpreter i.e. python3 program
(MD2-lab) python3 01.opti-cell.py 
      Step     Time          Energy         fmax
BFGS:    0 08:46:56      -15.377676       11.4782
BFGS:    1 08:46:56      -13.490951       45.3494
BFGS:    2 08:46:56      -15.659173        5.2412
BFGS:    3 08:46:56      -15.712135        2.3477
BFGS:    4 08:46:56      -15.724258        0.2503
BFGS:    5 08:46:56      -15.724388        0.0117
BFGS:    6 08:46:56      -15.724389        0.0001

============================================================
Cohesive energy=  -3.9310971482314847  [eV]
a=  4.062598383424775  [Angtrom]
(MD2-lab)

The first line in each of the program codes, points to the system python the correct line should be #!/usr/bin/env python3 which will select the python provided by the conda environment.

In fact it is better to change this line, since later when you plot some of the results, gnuplot is calling the programs directly and this leads to errors.

You can fix these lines by running sed -ie 's/#!\/usr\/bin\/python3/#!\/usr\/bin\/env python3/' */*.py in the top folder.

(MD2-lab) tree -L 1
.
├── 01.Static
├── 02.MD-1
├── 02.MD-2
├── Ag.lammps.eam
├── Al.lammps.eam
├── Au.lammps.eam
├── Ca.lammps.eam
├── Ce.lammps.eam
├── Cu.lammps.eam
├── Melting-comp-JChemPhys_136_144116.pdf
├── Ni.lammps.eam
├── PhysRevB.83.134118.pdf
├── Pt.lammps.eam
└── Rh.lammps.eam

(MD2-lab) sed -i 's/#!\/usr\/bin\/python3/#!\/usr\/bin\/env python3/' */*.py

Removing the installation

The conda environment is about 2GB large, so if you do not need it anymore, you can remove it.

(MD2-lab) connda deactivate
(base) conda env remove -n MD2-lab

Troubleshooting

If Python finds modules outside the conda environment (like the example below) - lines 4,6-8,10.

(MD2-lab) ase info platform Linux-5.15.0-47-generic-x86_64-with-glibc2.35 python-3.10.6 /home/user/miniconda3/envs/MD2-lab/bin/python3.10 ase-3.22.1 /home/user/.local/lib/python3.10/site-packages/ase numpy-1.23.3 /home/user/miniconda3/envs/MD2-lab/lib/python3.10/site-packages/numpy scipy-1.9.1 /home/user/.local/lib/python3.10/site-packages/scipy matplotlib-3.5.3 /home/user/.local/lib/python3.10/site-packages/matplotlib spglib-2.0.1 /home/user/.local/lib/python3.10/site-packages/spglib ase_ext not installed flask-2.2.2 /home/user/.local/lib/python3.10/site-packages/flask psycopg2 not installed pyamg not installed

Solution: Execute export PYTHONNOUSERSITE=True after you have activated the MD2-lab environment and check again to make sure that modules fromase info are pointing to the conda setup.

# check which python3 is default
(MD2-lab) which python3
/sw/apps/pm-tools/latest/rackham/conda_envs/MD2-lab/bin/python3

Make sure it points a python3 in the conda environment you activated.

Solution

# specify explicitly which python3 to run
(MD2-lab) /sw/apps/pm-tools/latest/rackham/conda_envs/MD2-lab/bin/python3   01.opti-cell.py 

On Rackham, look in your ~/.bashrc and remove all lines between

# >>> conda initialize >>>
...
# <<< conda initialize <<<

Log out and log in again, then follow the instructions above instructions.

Unexpected behavior or results

The original lab was setup and tested with the following versions of these tools

  • ase-3.18.1
  • LAMMPS - 7 Aug 2019
    Compiler: GNU C++ 7.4.0 with OpenMP 4.5

Pre-installed MD2-lab conda environment on Rackham

To use the pre-installed conda enviroment

module load conda
source conda_init.sh

(base) conda activate /sw/apps/pm-tools/latest/rackham/conda_envs/MD2-lab

Contacts:


tags: UPPMAX, SNIC,MD,conda,lab,education
Select a repo