Skip to content

Instantly share code, notes, and snippets.

View jmmshn's full-sized avatar

Jimmy Shen jmmshn

  • LLNL
  • Livermore
View GitHub Profile
@jmmshn
jmmshn / bash_eof.sh
Last active July 24, 2018 00:44
cat eof file in bash script
cat << EOF > FILENAME
#!/bin/bash
echo \$PWD
EOF
@jmmshn
jmmshn / iterm_ranger.scpt
Created June 20, 2018 06:58
Apple script for lauching ranger in iTerm
on run {input, parameters}
tell application "iTerm"
create window with default profile
tell front window
tell current session
write text ("ranger " & "; exit")
end tell
end tell
end tell
return input
@jmmshn
jmmshn / init_atomate.py
Last active July 24, 2018 21:07
[init_atomate.py] Python header for typical atomate workflow
%env FW_CONFIG_FILE=/Users/lik/.atomate/config/FW_config.yaml
from pymatgen import Structure
from atomate.vasp.workflows.base.core import get_wf
from fireworks import LaunchPad,fw_config
fw_config.CONFIG_FILE_DIR # you can finetune the configuration for each project using this parameter
from atomate.vasp.powerups import add_modify_incar, add_additional_fields_to_taskdocs, add_priority
from pymongo import MongoClient
import json
from pymatgen import MPRester
@jmmshn
jmmshn / tempfile_write.py
Created July 25, 2018 18:48
[tempfile handling] write a string to a temp file
import os
import tempfile
temp = tempfile.NamedTemporaryFile(mode='w+t')
try:
temp.write(string)
temp.seek(0)
print (temp.name)
finally:
temp.close()
@jmmshn
jmmshn / db_insert_tests.py
Created July 26, 2018 21:31
[Test atomate db insertion] function to help rapid prototyping of db insertion
from pymongo import MongoClient
import json
import pandas as pd
import numpy as np
from atomate.vasp.database import VaspCalcDb
def insert_task_incre(doc, db_file, name_root='test', **kwargs):
# open the database
with open('./test.db', 'r') as f:
db_dict = json.load(f)
@jmmshn
jmmshn / get_cart_pos.py
Created August 4, 2018 02:38
[Get Carteasian Position in pymatgen] obtain the cartesian position from fractional coordinates in pymatgen
cart_pos = np.dot(struct.lattice.matrix, frac_coord_vec)
@jmmshn
jmmshn / find_duplicates.mjs
Created August 28, 2018 00:12
[find_duplicates] Pring and sort by the number of duplicates
db.getCollection("chgcar_fs.files").aggregate([
{$group: {
_id: {task_id: "$metadata.task_id"},
uniqueIds: {$addToSet: "$metadata.task_id"},
count: {$sum: 1}
}
},
{$match: {
count: {"$gt": 1}
}
@jmmshn
jmmshn / check_struct_fws.py
Created November 13, 2018 23:02
[check_struct_fws] Check if a given structure is in the fireworks db
from maggma.stores import MongoStore
from pymatgen.analysis.structure_matcher import StructureMatcher, ElementComparator
from pymatgen import Structure
sm = StructureMatcher(comparator=ElementComparator(),
primitive_cell=False)
def check_fws( struct_in ):
js_fw_store = MongoStore("", "",
host="",
username="",
password="",
@jmmshn
jmmshn / injest_calcdir.py
Created December 7, 2018 19:16
[Injest CalcDir] Injest the calculation directory
from atomate.vasp.firetasks.parse_outputs import VaspDrone
drone = VaspDrone(parse_chgcar=True, parse_aeccar=True)
d = drone.assimilate('CALC_DIR')
@jmmshn
jmmshn / ase_plot_structs.py
Created December 7, 2018 23:45
[ase plotting] use the matplotlib functionailties of ASE to plot structs from different perspecties.
atoms = AseAtomsAdaptor.get_atoms(struct)
import matplotlib.pyplot as plt
from ase.visualize.plot import plot_atoms
from ase.lattice.cubic import FaceCenteredCubic
fig, ax = plt.subplots(2,2)
plt.subplots_adjust(wspace=0, hspace=0)
rot=['0x,0y,0z', '90x,0y,0z', '0x,90y,0z', '0x,0y,90z']
for itr, a in enumerate(ax.flatten()):
plot_atoms(atoms, a, radii=0.3, rotation=rot[itr], show_unit_cell=True, scale=0.5)