Skip to content

Commit 7bffa2b

Browse files
committed
inital commit
1 parent 86c5c4d commit 7bffa2b

File tree

3 files changed

+258
-0
lines changed

3 files changed

+258
-0
lines changed

highlight_atoms.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os,sys
2+
from rdkit import Chem
3+
from rdkit.Chem import AllChem
4+
from rdkit.Chem import Draw
5+
from rdkit.Chem.Draw import IPythonConsole
6+
7+
name2smiles = {}
8+
9+
pka_file_name = sys.argv[1]
10+
smiles_file_name = pka_file_name.split("_")[0]+".smiles"
11+
svg_file_name = pka_file_name.split(".")[0]+".svg"
12+
13+
smiles_file = open(smiles_file_name, "r")
14+
pka_file = open(pka_file_name, "r")
15+
16+
for line in smiles_file:
17+
words = line.split()
18+
name = words[0]
19+
smiles = words[1]
20+
name2smiles[name] = smiles
21+
22+
mols = []
23+
names = []
24+
atoms = []
25+
26+
for line in pka_file:
27+
words = line.split()
28+
name = words[0]
29+
smiles = name2smiles[name]
30+
atoms.append(map(int,words[1][:-1].split(",")))
31+
m = Chem.MolFromSmiles(smiles)
32+
mols.append(m)
33+
Chem.Kekulize(m)
34+
names.append(name)
35+
Draw.DrawingOptions.includeAtomNumbers=True
36+
37+
img = Draw.MolsToGridImage(mols,molsPerRow=4,subImgSize=(200,200),legends=[x for x in names],useSVG=True,highlightAtomLists=atoms)
38+
39+
40+
print svg_file_name
41+
svg_file = open(svg_file_name, 'w')
42+
svg_file.write(img.data)
43+
svg_file.close()
44+
os.system('sed -i "s/xmlns:svg/xmlns/" '+svg_file_name)

merge_svg.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import sys
2+
3+
def change_color(ellipse, name, find="#FF7F7F"):
4+
5+
red = "#e41a1c"
6+
green = "#4daf4a"
7+
8+
color = green
9+
10+
if name == "red":
11+
color = red
12+
13+
if find == "green":
14+
find = green
15+
16+
ellipse = ellipse.replace(find, color)
17+
18+
return ellipse
19+
20+
def merge_svg(svg_a, svg_b):
21+
22+
# svg_a = svg_a.split("\n")
23+
# svg_b = svg_b.split("\n")
24+
25+
for i, a in enumerate(svg_a):
26+
if "ellipse" in a:
27+
svg_a[i] = change_color(a, "green")
28+
29+
for i, b in enumerate(svg_b):
30+
if "ellipse" in b:
31+
svg_b[i] = change_color(b, "green")
32+
33+
for i, b in enumerate(svg_b):
34+
if b not in svg_a:
35+
b = change_color(b, "red", find="green")
36+
svg_a = svg_a[:i] + [b] + svg_a[i:]
37+
38+
svg_a = "\n".join(svg_a)
39+
40+
return svg_a
41+
42+
43+
if __name__ == "__main__":
44+
45+
svg_1_name = sys.argv[1]
46+
svg_2_name = sys.argv[2]
47+
48+
svg_1 = open(svg_1_name, 'r').readlines()
49+
svg_2 = open(svg_2_name, 'r').readlines()
50+
51+
svg = merge_svg(svg_1, svg_2)
52+
53+
output_name = svg_1_name.split(".")[0]
54+
output_name = output_name[:-1]+"combined"
55+
svg_file = open(output_name+".svg", 'w')
56+
svg_file.write(svg)
57+
svg_file.close()
58+

submit_batches_mopac

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/bin/bash
2+
3+
PARTITION=sauer # teach coms sauer
4+
NCPUS=8 # cores per job
5+
NBATCH=500 # input per batch
6+
EXTENSION=mop # extension to pack
7+
OUTEXT=out # extension to unpack
8+
9+
# Check ssh key is setup
10+
ssh_pri=`ssh-keygen -y -f ~/.ssh/id_rsa`
11+
ssh_pub=`cat ~/.ssh/id_rsa.pub`
12+
if [[ $ssh_pub != $ssh_pri* ]]; then
13+
14+
echo
15+
echo "SSH key not setup. Please run 'ssh-keygen' in the terminal,"
16+
echo "to setup a key-pair (ssh with no password), before running this"
17+
echo "script"
18+
echo
19+
20+
exit 4
21+
fi
22+
23+
# note
24+
# #SBATCH -w, --nodelist=asusnode103
25+
26+
PWD=`pwd`
27+
JOB=${PWD##*/}
28+
SUBMIT=qsub.tmp
29+
host=$HOSTNAME
30+
31+
32+
files=`ls -f *$EXTENSION`
33+
34+
# Remove input files which is already done
35+
out_files=`ls -f *.$OUTEXT 2> /dev/null`
36+
37+
for x in $out_files; do
38+
inp=${x%.*}.$EXTENSION
39+
files=`echo $files | sed "s/$inp//"`
40+
done
41+
42+
foo=( $files )
43+
nfiles=`echo "$files" | wc -w`
44+
45+
echo $files
46+
echo $nfiles
47+
48+
counter=0
49+
while [ $counter -lt $nfiles ]; do
50+
51+
tarfile=batch_${counter}.tar.gz
52+
outfile=batch_${counter}_log.tar.gz
53+
54+
tar -czf $tarfile ${foo[@]:$counter:$NBATCH}
55+
56+
cjob=$JOB\_\_$counter
57+
58+
cat > $SUBMIT <<!EOF
59+
#!/bin/bash
60+
#SBATCH --job-name=$cjob
61+
#SBATCH --nodes=1
62+
#SBATCH --cpus-per-task=$NCPUS
63+
#SBATCH --ntasks=1
64+
#SBATCH --error=$PWD/$cjob\_%j.stderr
65+
#SBATCH --output=$PWD/$cjob\_%j.stdout
66+
#SBATCH --time=100:00:00
67+
#SBATCH --partition=$PARTITION
68+
#SBATCH --no-requeue
69+
70+
71+
start=\`date +%s\`
72+
73+
74+
nodename=\$HOSTNAME
75+
echo 0 "Running on \$nodename"
76+
echo 0 "un-tar input files"
77+
78+
79+
mkdir /scratch/\$SLURM_JOB_ID
80+
cd /scratch/\$SLURM_JOB_ID
81+
82+
83+
cp $PWD/$tarfile .
84+
tar -xzf $tarfile
85+
86+
# MOPAC
87+
88+
cp -r /opt/mopac .
89+
cp -r /opt/intel/composer_xe_2013.1.117/compiler/lib/intel64 .
90+
export LD_LIBRARY_PATH=/scratch/\$SLURM_JOB_ID/intel64:$LD_LIBRARY_PATH
91+
export MKL_NUM_THREADS=1
92+
93+
run_calculation () {
94+
95+
input=\${1%.*}
96+
echo \$input
97+
/scratch/\$SLURM_JOB_ID/mopac/MOPAC2016.exe \$input > /dev/null 2> /dev/null
98+
99+
}
100+
101+
export -f run_calculation
102+
103+
# END MOPAC
104+
105+
106+
end=\`date +%s\`
107+
runtime=\$((end-start))
108+
echo \$runtime "run calculation"
109+
110+
111+
ls -f *.$EXTENSION | parallel -j$NCPUS "run_calculation {}"
112+
113+
114+
end=\`date +%s\`
115+
runtime=\$((end-start))
116+
echo \$runtime "tar output"
117+
118+
119+
tar -czf $outfile *.$OUTEXT
120+
cp $outfile $PWD
121+
122+
123+
end=\`date +%s\`
124+
runtime=\$((end-start))
125+
echo \$runtime "untar in $PWD"
126+
127+
128+
ssh sunray "cd $PWD && tar xzf $outfile"
129+
130+
131+
end=\`date +%s\`
132+
runtime=\$((end-start))
133+
echo \$runtime "done"
134+
135+
136+
convertsecs() {
137+
((h=\${1}/3600))
138+
((m=(\${1}%3600)/60))
139+
((s=\${1}%60))
140+
printf "%02d:%02d:%02d\n" \$h \$m \$s
141+
}
142+
143+
convertsecs \$runtime
144+
145+
!EOF
146+
147+
# submit batch
148+
sbatch $SUBMIT
149+
150+
# next
151+
let counter+=$NBATCH
152+
153+
done
154+
155+
156+

0 commit comments

Comments
 (0)