[chimera-dev] Send PDB and CCP4 selected to an external program

Eric Pettersen pett at cgl.ucsf.edu
Mon Feb 27 16:02:17 PST 2017


Hi Pablo,
	All Python files have a global attribute named __file__ that is the full path to that file.  Therefore you can use os.split() to get the folder that your Python code is in.  Presumably your executable is in some fixed place relative to your code so you should be able to easily construct a path to it based on the code folder.

—Eric

	Eric Pettersen
	UCSF Computer Graphics Lab


> On Feb 27, 2017, at 3:17 PM, Pablo Solar Rodríguez <pablosolar.r at gmail.com> wrote:
> 
> Hello dear Tom!
> 
> Thank you so much for your quick response. I already get the files paths with self.object_menu.getvalue().openedAs[0] and self.map_menu.volume().openedAs[0]. So thank you!
> 
> Now I've got a second problem relative to the predefined working path and cannot find any kind of solution with the existing doc. Hope you can help me...
> 
> To call the external program, I do:
> 
> cmd = ["/path/my_extension/external_program", mapSelected, pdbSelected, arg3, arg4, arg5]
> filename = "/path/my_rxtension/log.dat"
> logfile = open(filename, "w")
> logfile.flush()
> Popen(cmd, stdout=logfile,stderr=STDOUT, cwd="/path/my_extension/")
> 
> I would like the path to be dynamic to allow user to place my extension in the folder he/she wants. The question is, how can I set/get it? Imagine the folder where I put my extension is:
> 
> /path/
> 
> So I want to be able to get it. I tried to make:
> 
> os.getcwd(), os.path.dirname(), os.path.abspath(), os.curdir()
> 
> But I always get "/". I tried to make a settings.txt to set the path when my extension is loaded but, sincerely, I don't know how to define it to be setted on the initialization of the extension. I also tried to find the locations folder for extensions loaded in Favorites->Preferences without success. No solutions come to my mind at this moment, and maybe you could give an advice.
> 
> Thank you so much for your time. Working with Chimera is being harder than I thought at first.
> 
> Best regards, Pablo.
> 
> 2017-02-24 20:20 GMT+01:00 Tom Goddard <goddard at sonic.net <mailto:goddard at sonic.net>>:
> Hi Pablo,
> 
>   The typical approach is to write a temporary file for the PDB and the map, for example,
> 
> 	from Midas import write
> 	write(mol, map, “outfile.pdb”)
> 
> 	map.write_file(“outfile.mrc”)
> 
> The first two lines write out a pdb file.  The map is given as an argument to tell it to write the PDB relative to the map coordinate system (probably what you want for fitting).  The third line writes the map file in MRC format.  Chimera does not write CCP4 format, but MRC and CCP4 are almost identical and can probably be used interchangably by your code.  If you need the file suffix to be ccp4 you can instead use
> 
> 	map.write_file(“outfile.ccp4”, format=“mrc”)
> 
>   In some cases you the opened molecule and map may already come from a PDB file and map file and you could use those paths.  But molecules can also come from mmCIF or mol2 and maps can come from many different format files or be produced inside Chimera.  So relying on the original files won’t work in general.  But if you still want to pursue that all models (molecule and map Python objects have an openedAs attribute that has the file path and file type:
> 
> 	 mol.openedAs = (file_path, type, default_type, prefixable_type)
> 
> When the files are fetched from a database this does not give the local cached copy of the file.  For molecules the cached file path is simply not easy to get at, and for maps you can always get the local file path using map.data.path.
> 
> 	Tom
> 
> 
> 
>> On Feb 24, 2017, at 12:12 AM, Pablo Solar Rodríguez <pablo.solar at delogica.com <mailto:pablo.solar at delogica.com>> wrote:
>> 
>>  
>> Hello again dear mates!
>> 
>> I've been working those days in my extension and the GUI es almost finished. Now I want to fill this skeleton with the process logic. To understand between us, I have an external compiled program that is executed in shell this way:
>> 
>> ./bin/myProgram ./dir1/pdbselected.pdb ./dir/mapselected.ccp4 arg3 arg3 arg4
>> 
>> And for sure, in my .py test, it has to be executed as:
>> 
>> import subprocess
>> subprocess.call(["./Users/Solar/Desktop/parent/child1/child2/bin/myProgram",
>> "/Users/Solar/Desktop/parent/child1/child2/dir1/pdbselected.pdb", "/Users/Solar/Desktop/parent/child1/child2/dir1/mapselected.ccp4", "arg3", "arg4", "arg5"])
>> 
>> The problem is to execute this in Chimera as an extension. The coding I made for the PDB and the Map it's similar to the FitMap tool (in Volume Data), where I use:
>> 
>> ...
>> # PDB
>> from chimera import Molecule
>> mlist = [m for m in fit_object_models() if isinstance(m, Molecule)]
>> fstart = mlist[0] if mlist else None
>> from chimera.widgets import ModelOptionMenu
>> om = ModelOptionMenu(ff, labelpos = 'w', label_text = 'Fit ',
>> initialitem = fstart,
>> listFunc = fit_object_models,
>> sortFunc = compare_fit_objects,
>> command = self.object_chosen_cb)
>> om.grid(row = 0, column = 0, sticky = 'w')
>> self.object_menu = om
>> 
>> # Map
>> fm = Volume_Menu(ff, ' in map ')
>> fm.frame.grid(row = 0, column = 1, sticky = 'w')
>> self.map_menu = fm
>> --
>> 
>> The question is, how can I pass the PDB to the compiled program as it is expected? Or, another possible solution, the paths of the PDB and the Map loaded in Chimera? I didn't found any friendly doc (methods, info and so on) about this and and I'm a mess :/
>> 
>> Thank you in advance dear coworkers!
>> 
>> Pablo
>>  
>> _______________________________________________
>> Chimera-dev mailing list
>> Chimera-dev at cgl.ucsf.edu <mailto:Chimera-dev at cgl.ucsf.edu>
>> http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev <http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev>
> 
> 
> _______________________________________________
> Chimera-dev mailing list
> Chimera-dev at cgl.ucsf.edu <mailto:Chimera-dev at cgl.ucsf.edu>
> http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev <http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev>
> 
> 
> 
> 
> -- 
> 
> Pablo Solar Rodríguez
> 
> pablosolar.r at gmail.com <mailto:pablosolar.r at gmail.com>
> 
> _______________________________________________
> Chimera-dev mailing list
> Chimera-dev at cgl.ucsf.edu
> http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-dev/attachments/20170227/a9b53a6c/attachment.html>


More information about the Chimera-dev mailing list