[Chimera-users] Way to extract path to file from model ID

Oliver Clarke olibclarke at gmail.com
Thu Sep 24 14:26:28 PDT 2015


That worked - here is the amended python snippet in case it is useful to anyone else:

def cmd_lowpass(lowpass,args):
  from Midas.midas_text import doExtensionFunc
  def lowpass(model,resol):
    import os
    from chimera import runCommand
    from chimera import openModels
    import subprocess
    import sys
    #You may need to change the below to .bash_profile if on mac.
    #You must have EMAN2 in your bash path for this to work correctly.
    bashrc_path=os.path.expanduser("~/.bashrc")
    freq=1.0/resol
    command="cd ~; system mkdir chimera_tmp; cd chimera_tmp"
    runCommand(command)
    pathvar=os.path.expanduser("~/chimera_tmp")
    os.chdir(pathvar)
    e2string="--process=filter.lowpass.gauss:cutoff_freq="+str(freq)
    model_no=int(model[1])
    mrc_in=openModels.list()[model_no].openedAs[0]
    mrc_out=pathvar+"/lowpass.mrc"
    e2command="source "+bashrc_path+"; bash -c \"e2proc3d.py"+" "+mrc_in+" "+mrc_out+" "+e2string+"\""
    for mol in openModels.list():
      if mol.openedAs[0]=="lowpass.mrc":
        runCommand("close {}".format(mol))
    proc=subprocess.Popen(e2command,stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
    out, err = proc.communicate()
    print 'stdout:', out
    print 'stderr:', err
    runCommand("open lowpass.mrc")
  doExtensionFunc(lowpass,args)
from Midas.midas_text import addCommand
addCommand("lowpass", cmd_lowpass, help=False)


> On Sep 24, 2015, at 5:00 PM, Oliver Clarke <olibclarke at gmail.com> wrote:
> 
> Aha, great. Thanks Eric!’
> 
> Oliver.
>> On Sep 24, 2015, at 4:58 PM, Eric Pettersen <pett at cgl.ucsf.edu> wrote:
>> 
>> If a model has an “openedAs” attribute (which I believe all models opened from files have), then openedAs[0] is the path of the input file.
>> 
>> —Eric
>> 
>>> On Sep 24, 2015, at 1:39 PM, Oliver Clarke <olibclarke at gmail.com> wrote:
>>> 
>>> Hi all, I’m wondering, is there any way (presumably via a python function) to get the path to the original file from the model ID?
>>> 
>>> I’ve written a little python jiffy (below) so I can lowpass filter maps to a specified resolution on the fly inside chimera using EMAN, but is quite slow because I need to first write a copy of the map out (so I know where it is) and then modify it. If anyone knows of an easier way to do such things I would be most grateful.
>>> 
>>> Cheers,
>>> Oli.
>>> 
>>> Script:
>>> 
>>> def cmd_lowpass(lowpass,args):
>>> from Midas.midas_text import doExtensionFunc
>>> def lowpass(model,resol):
>>>  import os
>>>  from chimera import runCommand
>>>  import subprocess
>>>  import sys
>>>  #You may need to change the below to .bash_profile if on mac.
>>>  #You must have EMAN2 in your bash path for this to work correctly.
>>>  #If running multiple times, you need to close the first instance of lowpass.mrc before creating a second.
>>>  bashrc_path=os.path.expanduser("~/.bashrc")
>>>  freq=1.0/resol
>>>  command="cd ~; system mkdir chimera_tmp; cd chimera_tmp; volume "+model+" save ./tmp1.mrc"
>>>  runCommand(command)
>>>  pathvar=os.path.expanduser("~/chimera_tmp")
>>>  os.chdir(pathvar)
>>>  e2string="--process=filter.lowpass.gauss:cutoff_freq="+str(freq)
>>>  print(e2string)
>>>  mrc_in=pathvar+"/tmp1.mrc"
>>>  mrc_out=pathvar+"/lowpass.mrc"
>>>  e2command="source "+bashrc_path+"; bash -c \"e2proc3d.py"+" "+mrc_in+" "+mrc_out+" "+e2string+"\""
>>>  print(e2command)
>>>  proc=subprocess.Popen(e2command,stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
>>>  out, err = proc.communicate()
>>>  print 'stdout:', out
>>>  print 'stderr:', err
>>>  runCommand("open lowpass.mrc")
>>> doExtensionFunc(lowpass,args)
>>> from Midas.midas_text import addCommand
>>> addCommand("lowpass", cmd_lowpass, help=False)
>>> _______________________________________________
>>> Chimera-users mailing list
>>> Chimera-users at cgl.ucsf.edu
>>> http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
>>> 
>> 
> 




More information about the Chimera-users mailing list