Scientific Computing Notes


Fortran


Compile Fortran file and run

gfortran run_model.f90 -o run_model.o

./run_model

Compile into object files (-c) and link the object files with main program

gfortran -c -O3 -fPIC model.f90

gfortran -c -O3 -fPIC solver.f

gfortran -O3 -fPIC main.f90 model.o solver.o -o main.o

./main

Debugging

gfortran -g3 -fcheck=all    -Wall -fbacktrace -fsanatize=undefined foo.f90 bar.f90 -o fout

gfortran -g3 -fcheck=bounds -Wall -fbacktrace -fsanatize=address   foo.f90 bar.f90 -o fout

gfortran -g3 -fcheck=bounds -Wall -fbacktrace -fsanatize=leak      foo.f90 bar.f90 -o fout

Tools for Fortran


F77 to F90

FoBiS.py

FORD

JSON-Fortran

f90wrap

f90wrap


gfortran -c -O3 -fPIC *.f90 *.f

f90wrap -v -k kind_map --default-to-inout -m MODULE *.f90 *.f

f2py-f90wrap -c -m _MODULE OBJ_FILES f90wrap_*.f90 *.o

Example:

gfortran -c -O3 -fPIC DerivedTypes.f90 SprayColumnModel.f90 nleq1.f

f90wrap -v -k kind_map --default-to-inout -m spraycolumn DerivedTypes.f90 SprayColumnModel.f90

f2py-f90wrap -c -m _spraycolumn f90wrap_*.f90 *.o

Issues:

OpenMPI


mpifort *.f90 -o main

mpirun -n 4 ./main

OpenMP


export OMP_NUM_THREADS=4

gfortran -fopenmp

Cython


gfortran foo.f90 run_foo_from_fortran.f90 -o fout

gfortran -I /usr/include/python3.4m -L /usr/lib/python3.4 -fPIC -c foo.f90 foo_wrap.f90

gcc -I /usr/include/python3.4m -L /usr/lib/python3.4 -c run_foo_from_c.c foo.f90 foo_wrap.f90

Call setup.py to compile .pyx file:

python setup.py build_ext --inplace

PostgreSQL


Setup on Ubuntu

Check https://www.postgresql.org/download/linux/ubuntu/

Install

sudo apt-get install postgresql

Login with system account postgres:

sudo -i -u postgres

Create user:

createuser user_name -P --interactive

Create database:

createdb database_name

Use psql as commmand line client:

psql

Setup in conda environment

https://www.postgresql.org/docs/9.1/static/server-start.html

https://www.postgresql.org/docs/9.1/static/creating-cluster.html

Cheat sheet for psql interactive console:

\d table_name  - Examine a table

\dt - List the tables in the selected schema

\dd - Show comment for object

\q  - quit

SQL cheat sheet:

CREATE USER user_name;

ALTER ROLE user_name WITH SUPERUSER;

CREATE DATABASE database_name WITH ENCODING 'UTF-8';

Creating molecular graphs (.png) with Python and RDKit


http://www.rdkit.org/docs/Install.html

http://www.rdkit.org/docs/GettingStartedInPython.html#drawing-molecules

import csv
from rdkit import Chem
from rdkit.Chem import Draw

#Read in CSV file with SMILES strings
csvfile_chemicals = open('chemdata.csv', 'r')
reader_chemicals  = csv.reader(csvfile_chemicals)

# Select rows in CSV file, create the graphs and save in current folder
for idx, row in enumerate(reader_chemicals):
    mol = Chem.MolFromSmiles(row[2])
    file_name = 'mol_graph' + str(idx) + '.png'
    Draw.MolToFile(mol, file_name)

Spacemacs


Install latest version of emacs on Ubuntu

sudo add-apt-repository ppa:ubuntu-elisp/ppa
sudo apt-get update
sudo apt-get install emacs-snapshot
sudo update-alternatives --config emacs

Clone the Spacemacs config

git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d

Issues

Solution:

sudo git clone --depth 1 --branch release https://github.com/adobe-fonts/source-code-pro.git /usr/share/fonts/opentype/scp
sudo fc-cache -f -v

(Use git pull for updates)

Solution:

sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git

LaTeX


sudo apt-get install texlive-base texlive-latex-extras texlive-science texlive-xetex

Solution:

wget -q http://tug.org/fonts/getnonfreefonts/install-getnonfreefonts
sudo texlua ./install-getnonfreefonts
sudo chmod u+x install-getnonfreefonts
sudo getnonfreefonts --sys -a