[chimera-dev] opening models

Eric Pettersen pett at cgl.ucsf.edu
Fri Dec 15 13:28:30 PST 2006


On Dec 15, 2006, at 1:07 PM, Randy Heiland wrote:

> Eric,
> Need a bit more help on this... how can I invoke this reader
> programmatically from my plugin and display the model in the viewer
> window?  Til now, with PDB formatted files, I've done:
>
>       fp = open(tmpfile.name, 'w')
>       fp.write(pdbstr)
>       fp.close()
>       self.model = chimera.openModels.open(tmpfile.name, type='PDB',
> identifyAs=id[0])

If your temp file's name ends in '.sdf' then you don't have to supply  
a 'type' keyword to openModels.open().  If not, then with the code I  
gave you the 'type' would be "Structure Data Format" (it's the  
"fileType" variable in ReadSDF/fileInfo.py).  You might want to  
import that variable and use it instead of a fixed string, because in  
the next release of Chimera the string will be "MDL MOL/SDF" since I  
enhanced the reader to handle MOL files as well.

Also, openModels.open() always returns a _list_ of models, even if  
the input only creates one model.

> Now I have a 'pdbstr' that's really an sdf format, and when I try to
> substitue type='PDB' w/ 'SDF', it doesn't recognize it.
>
> And when I try the following, it doesn't complain, however no model is
> displayed:
> import ReadSDF
>
>       fp = open(tmpfile.name, 'w')
>       fp.write(sdfstr)
>       fp.close()
>       self.model = ReadSDF.readSDF(tmpfile.name)

The readSDF() function returns a list of models.  To add them to the  
list of open models, use chimera.openModels.add(), probably like this:

	self.models = ReadSDF.readSDF(tmpfile.name)
	chimera.openModels.add(self.models)

--Eric



More information about the Chimera-dev mailing list