1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
Author: Tatiana Malygina <merlettaia@gmail.com>
Description: fix relative paths in example scripts
Some example scripts are intended to be used from directory they are located
at. However, some of them use files located in different directory, which is
given by relative path (e.g., "../../test/dat/pept.pdb") or path based on
$PYMOL_PATH variable value. At the same time these scripts write output
(if any present) to current directory.
.
These fixes enable users to call example scripts from different directories
where they have write access. $PYMOL_PATH location addressed in examples
path is incorrect, because in Debian package it points to different location.
This script also solves this problem where it is possible.
Last-Update: 2016-08-14
--- a/examples/chempy/generate_amber.py
+++ b/examples/chempy/generate_amber.py
@@ -1,10 +1,12 @@
# python
-
+import pymol
from chempy import io
from chempy import protein
from chempy import protein_amber99
-model= io.pdb.fromFile("../../test/dat/pept.pdb")
+from inspect import getsourcefile
+current_file_dir = os.path.dirname(os.path.abspath(getsourcefile(lambda:0)))
+model= io.pdb.fromFile(os.path.join(current_file_dir, "../../test/dat/pept.pdb"))
model= protein.generate(model,forcefield=protein_amber99)
@@ -16,4 +18,3 @@ print " prot: net partial charge on prot
print " prot: (this should be integral)!"
io.pkl.toFile(model,"generate_amber.pkl")
-
--- a/examples/chempy/generate_mmff.py
+++ b/examples/chempy/generate_mmff.py
@@ -1,5 +1,5 @@
# python
-
+import pymol
from chempy import io
from chempy import protein
from chempy import protein_mmff
@@ -12,8 +12,9 @@ from chempy import bond_mmff
#protein_mmff.check_sum(protein_mmff.n_terminal)
#print 'c_terminal'
#protein_mmff.check_sum(protein_mmff.c_terminal)
-
-model= io.pdb.fromFile("../../test/dat/pept.pdb")
+from inspect import getsourcefile
+current_file_dir = os.path.dirname(os.path.abspath(getsourcefile(lambda:0)))
+model= io.pdb.fromFile(os.path.join(current_file_dir, "../../test/dat/pept.pdb"))
model= protein.generate(model,forcefield=protein_mmff,bondfield=bond_mmff)
@@ -28,4 +29,3 @@ print " prot: net partial charge on prot
print " prot: (this should be integral)!"
io.pkl.toFile(model,"generate_mmff.pkl")
-
--- a/examples/launching/launch_demo.py
+++ b/examples/launching/launch_demo.py
@@ -9,7 +9,13 @@ pymol.finish_launching()
# Now we can import cmd
from pymol import cmd
-
-cmd.load("$PYMOL_PATH/test/dat/pept.pdb")
+if os.path.exists("$PYMOL_PATH/test/dat/pept.pdb"):
+ cmd.load("$PYMOL_PATH/test/dat/pept.pdb")
+else:
+ from inspect import getsourcefile
+ current_file_dir = os.path.dirname(os.path.abspath(getsourcefile(lambda:0)))
+ cmd.load(os.path.join(current_file_dir, "../../test/dat/pept.pdb"))
+# Note that in typical Debian package installation test/... directory would be
+# located at /usr/share/pymol directory, and $PYMOL_PATH will point to different
+# location.
cmd.show("sticks")
-
--- a/examples/devel/chempy_model02.py
+++ b/examples/devel/chempy_model02.py
@@ -22,10 +22,14 @@ import time
# cont = False
#
-cont = True
+cont = False
# first we need a model
-
-cmd.load("$PYMOL_PATH/test/dat/pept.pdb","demo")
+if os.path.exists("$PYMOL_PATH/test/dat/pept.pdb"):
+ cmd.load("$PYMOL_PATH/test/dat/pept.pdb","demo")
+else:
+ from inspect import getsourcefile
+ current_file_dir = os.path.dirname(os.path.abspath(getsourcefile(lambda:0)))
+ cmd.load(os.path.join(current_file_dir, "../../test/dat/pept.pdb"), "demo")
# let's dress it up a little bit
@@ -63,6 +67,3 @@ while cont:
# C data structure...
# Cheers, warren@delanoscientific.com
-
-
-
--- a/examples/devel/chempy_model03.py
+++ b/examples/devel/chempy_model03.py
@@ -7,7 +7,12 @@ import time
# first we need a model
-cmd.load("$PYMOL_PATH/test/dat/pept.pdb","demo")
+if os.path.exists("$PYMOL_PATH/test/dat/pept.pdb"):
+ cmd.load("$PYMOL_PATH/test/dat/pept.pdb","demo")
+else:
+ from inspect import getsourcefile
+ current_file_dir = os.path.dirname(os.path.abspath(getsourcefile(lambda:0)))
+ cmd.load(os.path.join(current_file_dir, "../../test/dat/pept.pdb"), "demo")
# let's dress it up a little bit
@@ -38,4 +43,3 @@ cmd.mplay()
# by default, PyMOL plays ~30 fps.
# "set movie_delay=0" to see maximum speed...
-
--- a/examples/devel/count_molecules.py
+++ b/examples/devel/count_molecules.py
@@ -1,7 +1,12 @@
# This script illustrates how you can use PyMOL to count the
# number of molecules in a selection
-cmd.load("$PYMOL_PATH/test/dat/1tii.pdb")
+if os.path.exists("$PYMOL_PATH/test/dat/1tii.pdb"):
+ cmd.load("$PYMOL_PATH/test/dat/1tii.pdb")
+else:
+ from inspect import getsourcefile
+ current_file_dir = os.path.dirname(os.path.abspath(getsourcefile(lambda:0)))
+ cmd.load(os.path.join(current_file_dir, "../../test/dat/1tii.pdb"))
input_sele = "1tii and polymer"
@@ -24,4 +29,3 @@ if cmd.select(iter_sele, input_sele)>0:
print "(%s) contains %d molecules total."%(input_sele, mole_cnt)
-
--- a/examples/devel/sd_annotate.pml
+++ b/examples/devel/sd_annotate.pml
@@ -3,7 +3,6 @@
from pymol.wizard.annotation import load_annotated_sdf
# add this function to the command language
-
cmd.extend('load_annotated_sdf',load_annotated_sdf)
# activate the annotation wizard
@@ -15,6 +14,4 @@ wizard annotation
set wizard_prompt_mode,3
# now load an SD file
-
load_annotated_sdf demo.sdf
-
--- a/examples/devel/webgui02.py
+++ b/examples/devel/webgui02.py
@@ -16,6 +16,10 @@ from chempy.sdf import SDF
# example 3D sd file
input_sdf = os.environ['PYMOL_PATH']+"/test/dat/ligs3d.sdf"
+if not os.path.exists(input_sdf):
+ from inspect import getsourcefile
+ current_file_dir = os.path.dirname(os.path.abspath(getsourcefile(lambda:0)))
+ input_sdf = os.path.join(current_file_dir, "../../test/dat/ligs3d.sdf")
class SafeDict(dict):
'''
--- a/examples/cookbook/multiclip_ray.pml
+++ b/examples/cookbook/multiclip_ray.pml
@@ -1,7 +1,6 @@
# example script for creation of an image with a slice region
-
-load $PYMOL_PATH/test/dat/1tii.pdb
+load /usr/share/pymol/test/dat/1tii.pdb
orient
--- a/examples/devel/povray01.py
+++ b/examples/devel/povray01.py
@@ -4,7 +4,12 @@ import os
if not ('pept' in cmd.get_names()):
cmd.delete('all')
util.ray_shadows('heavy')
- cmd.do('load $PYMOL_PATH/test/dat/pept.pdb')
+ example_path = "$PYMOL_PATH/test/dat/pept.pdb"
+ if not os.path.exists(example_path):
+ from inspect import getsourcefile
+ current_file_dir = os.path.dirname(os.path.abspath(getsourcefile(lambda:0)))
+ example_path = os.path.join(current_file_dir, "../../test/dat/pept.pdb")
+ cmd.do('load ' + example_path)
cmd.do('set surface_quality=1')
cmd.do('show surface;hide lines;')
cmd.zoom('all',10)
@@ -25,6 +30,5 @@ for x in xrange(-30,30,5):
f.write("box {<-17,17,-120>,<13,15,-160> pigment {color Red}}\n")
f.close()
cmd.refresh()
-os.system("x-povray +Itmp_pymol.pov +Otmp_pymol.png +W300 +H300 +A")
+os.system("povray +Itmp_pymol.pov +Otmp_pymol.png +W300 +H300 +A")
cmd.load_png('tmp_pymol.png')
-
--- a/examples/devel/mutate01.pml
+++ b/examples/devel/mutate01.pml
@@ -4,7 +4,7 @@
# load a structure
-load $PYMOL_PATH/test/dat/pept.pdb
+load /usr/share/pymol/test/dat/pept.pdb
# activate the mutagensis wizard
|