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

Index: pymol/examples/chempy/generate_amber.py
===================================================================
--- pymol.orig/examples/chempy/generate_amber.py
+++ pymol/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")
-
Index: pymol/examples/chempy/generate_mmff.py
===================================================================
--- pymol.orig/examples/chempy/generate_mmff.py
+++ pymol/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")
-
Index: pymol/examples/launching/launch_demo.py
===================================================================
--- pymol.orig/examples/launching/launch_demo.py
+++ pymol/examples/launching/launch_demo.py
@@ -10,7 +10,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")
-
Index: pymol/examples/devel/chempy_model02.py
===================================================================
--- pymol.orig/examples/devel/chempy_model02.py
+++ pymol/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
-
-
-
Index: pymol/examples/devel/chempy_model03.py
===================================================================
--- pymol.orig/examples/devel/chempy_model03.py
+++ pymol/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...
-
Index: pymol/examples/devel/count_molecules.py
===================================================================
--- pymol.orig/examples/devel/count_molecules.py
+++ pymol/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"
 
Index: pymol/examples/devel/sd_annotate.pml
===================================================================
--- pymol.orig/examples/devel/sd_annotate.pml
+++ pymol/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
-
Index: pymol/examples/devel/webgui02.py
===================================================================
--- pymol.orig/examples/devel/webgui02.py
+++ pymol/examples/devel/webgui02.py
@@ -18,6 +18,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):
     '''
Index: pymol/examples/cookbook/multiclip_ray.pml
===================================================================
--- pymol.orig/examples/cookbook/multiclip_ray.pml
+++ pymol/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
 
Index: pymol/examples/devel/povray01.py
===================================================================
--- pymol.orig/examples/devel/povray01.py
+++ pymol/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 range(-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')
-
Index: pymol/examples/devel/mutate01.pml
===================================================================
--- pymol.orig/examples/devel/mutate01.pml
+++ pymol/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
 
