Skip to content

Instantly share code, notes, and snippets.

View Mahdisadjadi's full-sized avatar

mahdi sadjadi Mahdisadjadi

View GitHub Profile
@Mahdisadjadi
Mahdisadjadi / file_refiner.py
Last active August 29, 2015 14:21
This code is written to import a file, start to read the lines after a particular line and stop on a particular line. Finally results are converted to float numbers and written in a file.
'''
File Refiner
May 18 2015
This code is written to import a file, start to read the lines after a particular line
and stop on a particular line. Finally results will convert to float number and write
in a file.
Assuming the code and file.crd are in the same directory, and we want to miss first 5 lines
and extract 239 lines after that, one should type:
@Mahdisadjadi
Mahdisadjadi / extension_finder.sh
Last active September 30, 2015 00:41
Find files with an extension and copy them to a target directory
#!/bin/bash
### find files with ".f" extension in the current directory
### copy them to directory "dirx"
ls -d -1 $PWD/*.f* | xargs -I{} cp "{}" dirx
@Mahdisadjadi
Mahdisadjadi / Optimizer.py
Created February 22, 2016 05:28 — forked from jiahao/Optimizer.py
Pure Python implementation of some numerical optimizers
#!/usr/bin/env python
'''
Pure Python implementation of some numerical optimizers
Created on Jan 21, 2011
@author Jiahao Chen
'''
@Mahdisadjadi
Mahdisadjadi / core numbers
Last active March 7, 2016 22:16
Return the number of CPUs in the system
python -c 'import multiprocessing as mp; print(mp.cpu_count())'
@Mahdisadjadi
Mahdisadjadi / delete from list
Created March 7, 2016 22:11
Delete files when list of names is in a file
# This removes files where paths are listed in a file named "file.dat".
# for running, type:
# python3 script.py file.dat
import sys
import os
paths = sys.argv[1]
with open(paths) as f:
for line in f:
os.remove(line.rstrip('\n'))
@Mahdisadjadi
Mahdisadjadi / stop_running_jobs.sh
Created March 13, 2016 04:52
Stop all running jobs on the cluster
## Find all running jobs, take their JOB ID and delete them.
qstat | awk -F " " '{print $1}' | xargs qdel
@Mahdisadjadi
Mahdisadjadi / normalized_array.py
Created April 8, 2016 01:23
Numpy function to normalize an array with arbirtray shape in respect to different norms and arbitrary axis
## All the credit goes to Eelco Hoogendoorn
## http://stackoverflow.com/a/21032099/3349443
def normalized(a, axis=-1, order=2):
norms = np.atleast_1d(np.linalg.norm(a, order, axis))
norms[norms==0] = 1
return a / np.expand_dims(norms, axis)
@Mahdisadjadi
Mahdisadjadi / Tight-Binding Calculation of the Band Structure of Silicon.ipynb The band structure of Silicon is calculated using the empirical tight-binding method implemented in the Python programming language. Only interactions between first nearest neighbors are taken into account. The energy splittings for Silicon at symmetry points appear to be somewhat accurate to accepted values, although second neighbors will have …
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Mahdisadjadi
Mahdisadjadi / Self-Consistent Density Functional Theory Calculations with Quantum ESPRESSO.ipynb Silicon, Aluminum, Iron, and Graphene are characterized with a popular Fortran implementation of the self-consistent density functional theory -- Quantum ESPRESSO. An introduction to DFT and using QE is given, and results for Silicon are compared with those of previous calculations using the empirical pseudopotential and tight-binding methods.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Mahdisadjadi
Mahdisadjadi / html_remover.py
Last active October 22, 2016 23:28
To remove ".html" from all links within html pages - I wrote this to fix this issue: https://github.com/emckiernan/whyopenresearch/issues/5
import codecs # to read html
from bs4 import BeautifulSoup # to parse html
import glob # to find all files with a pattern
pages = glob.glob("*.html")
for page in pages:
# loop through all files
name = page.split(".")[0]
print (name)
html=codecs.open(page, 'r') # read html