Re: [Jmol-users] Loading MMTF programmatically
Thanks Bob, that works great. I didn't know that the filename could be null if the reader is supplied. I doubt anyone cares about the details, but if so see https://github.com/biojava/biojava/pull/570 -Spencer On Mon, Aug 29, 2016 at 3:15 PM, Robert Hansonwrote: > > You can now just use > > viewer.openReader("filename", reader) > > where reader is one of byte[] or BufferedInputStream or Reader > > I'm not catching how Jmol is fitting in there in terms of loading an MMTF > file. How does that reading fit into BioJava's writing? > > > Bob > > > > On Sun, Aug 28, 2016 at 3:48 PM, Spencer Bliven > wrote: > >> I have a method writeToOutputStream(Structure structure, OutputStream >> outputStream) that does the mmtf writing. I have flexibility in what >> type of OutputStream to use. The byte[] is accessible using a >> ByteArrayOutputStream. If it makes more sense to pass an input stream, I >> guess this should be possible too using PipedInputStream. >> >> Is this the most efficient way to communicate with Jmol given that it's >> embedded in the same process? For instance, could I just populate some data >> structure directly? (I might still go with MMTF, since it's fully >> implemented already) >> >> -Spencer >> >> >> On Fri, Aug 26, 2016 at 5:02 PM, Robert Hanson >> wrote: >> >>> It would be totally inconvenient to treat the byte[] mmtf data as String >>> data. >>> You can cache the binary data as a byte array and then pass a cache:// >>> protocol. >>> Way better would be to pass the data as a buffered stream, but I don't >>> think that is set up in Jmol. >>> >>> You have the data in what form? Full byte array? BufferedInputStream? >>> >>> The MMTF reader needs a javajs.api.GenericBinaryDocument. >>> This it gets from jmol.adapter.smarter.SmarterJm >>> olAdapter.getAtomSetCollectionFromReader. >>> >>> I think I can tweak viewer.loadModelFromFile to allow you to feed it a >>> BufferedInputStream. Right now it is only set up for a java.io.Reader. >>> >>> Will that work for you? >>> >>> Bob >>> >>> >>> >>> >>> >>> On Fri, Aug 26, 2016 at 7:46 AM, Spencer Bliven < >>> spencer.bli...@gmail.com> wrote: >>> I'm trying to update the way BioJava interacts with Jmol. We're currently loading structures into Jmol by converting them to PDB format and passing that string to JmolViewer.openStringInline(). Now that Jmol 14.6 is available in maven, we need to move away from PDB. My first choice would be to use MMTF as the exchange format. Is there a way to pass MMTF to Jmol? Resolver.determineAtomSetCollectionReader failed (probably correctly) to recognize an MMTF binary stream when converted to a string using the default encoding, so openStringInline() doesn't work. Possibly related, the mmtf demo at http://chemapps.stolaf.edu/ jmol/jsmol/mmtf.htm gives an unrecognized file format error for me. -Spencer -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users >>> >>> >>> -- >>> Robert M. Hanson >>> Larson-Anderson Professor of Chemistry >>> St. Olaf College >>> Northfield, MN >>> http://www.stolaf.edu/people/hansonr >>> >>> >>> If nature does not answer first what we want, >>> it is better to take what answer we get. >>> >>> -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900 >>> >>> >>> >>> -- >>> >>> ___ >>> Jmol-users mailing list >>> Jmol-users@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/jmol-users >>> >>> >> >> >> -- >> >> ___ >> Jmol-users mailing list >> Jmol-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/jmol-users >> >> > > > -- > Robert M. Hanson > Larson-Anderson Professor of Chemistry > St. Olaf College > Northfield, MN > http://www.stolaf.edu/people/hansonr > > > If nature does not answer first what we want, > it is better to take what answer we get. > > -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900 > > > > -- > > ___ > Jmol-users mailing list > Jmol-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jmol-users > > -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Loading MMTF programmatically
You can now just use viewer.openReader("filename", reader) where reader is one of byte[] or BufferedInputStream or Reader I'm not catching how Jmol is fitting in there in terms of loading an MMTF file. How does that reading fit into BioJava's writing? Bob On Sun, Aug 28, 2016 at 3:48 PM, Spencer Blivenwrote: > I have a method writeToOutputStream(Structure structure, OutputStream > outputStream) that does the mmtf writing. I have flexibility in what type > of OutputStream to use. The byte[] is accessible using a > ByteArrayOutputStream. If it makes more sense to pass an input stream, I > guess this should be possible too using PipedInputStream. > > Is this the most efficient way to communicate with Jmol given that it's > embedded in the same process? For instance, could I just populate some data > structure directly? (I might still go with MMTF, since it's fully > implemented already) > > -Spencer > > > On Fri, Aug 26, 2016 at 5:02 PM, Robert Hanson wrote: > >> It would be totally inconvenient to treat the byte[] mmtf data as String >> data. >> You can cache the binary data as a byte array and then pass a cache:// >> protocol. >> Way better would be to pass the data as a buffered stream, but I don't >> think that is set up in Jmol. >> >> You have the data in what form? Full byte array? BufferedInputStream? >> >> The MMTF reader needs a javajs.api.GenericBinaryDocument. >> This it gets from jmol.adapter.smarter.SmarterJm >> olAdapter.getAtomSetCollectionFromReader. >> >> I think I can tweak viewer.loadModelFromFile to allow you to feed it a >> BufferedInputStream. Right now it is only set up for a java.io.Reader. >> >> Will that work for you? >> >> Bob >> >> >> >> >> >> On Fri, Aug 26, 2016 at 7:46 AM, Spencer Bliven > > wrote: >> >>> I'm trying to update the way BioJava interacts with Jmol. We're >>> currently loading structures into Jmol by converting them to PDB format and >>> passing that string to JmolViewer.openStringInline(). Now that Jmol 14.6 is >>> available in maven, we need to move away from PDB. >>> >>> My first choice would be to use MMTF as the exchange format. Is there a >>> way to pass MMTF to Jmol? Resolver.determineAtomSetCollectionReader >>> failed (probably correctly) to recognize an MMTF binary stream when >>> converted to a string using the default encoding, so openStringInline() >>> doesn't work. >>> >>> Possibly related, the mmtf demo at http://chemapps.stolaf.edu/ >>> jmol/jsmol/mmtf.htm gives an unrecognized file format error for me. >>> >>> -Spencer >>> >>> >>> -- >>> >>> ___ >>> Jmol-users mailing list >>> Jmol-users@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/jmol-users >>> >>> >> >> >> -- >> Robert M. Hanson >> Larson-Anderson Professor of Chemistry >> St. Olaf College >> Northfield, MN >> http://www.stolaf.edu/people/hansonr >> >> >> If nature does not answer first what we want, >> it is better to take what answer we get. >> >> -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900 >> >> >> >> -- >> >> ___ >> Jmol-users mailing list >> Jmol-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/jmol-users >> >> > > > -- > > ___ > Jmol-users mailing list > Jmol-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jmol-users > > -- Robert M. Hanson Larson-Anderson Professor of Chemistry St. Olaf College Northfield, MN http://www.stolaf.edu/people/hansonr If nature does not answer first what we want, it is better to take what answer we get. -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900 -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Loading MMTF programmatically
I have a method writeToOutputStream(Structure structure, OutputStream outputStream) that does the mmtf writing. I have flexibility in what type of OutputStream to use. The byte[] is accessible using a ByteArrayOutputStream. If it makes more sense to pass an input stream, I guess this should be possible too using PipedInputStream. Is this the most efficient way to communicate with Jmol given that it's embedded in the same process? For instance, could I just populate some data structure directly? (I might still go with MMTF, since it's fully implemented already) -Spencer On Fri, Aug 26, 2016 at 5:02 PM, Robert Hansonwrote: > It would be totally inconvenient to treat the byte[] mmtf data as String > data. > You can cache the binary data as a byte array and then pass a cache:// > protocol. > Way better would be to pass the data as a buffered stream, but I don't > think that is set up in Jmol. > > You have the data in what form? Full byte array? BufferedInputStream? > > The MMTF reader needs a javajs.api.GenericBinaryDocument. > This it gets from jmol.adapter.smarter.SmarterJmolAdapter. > getAtomSetCollectionFromReader. > > I think I can tweak viewer.loadModelFromFile to allow you to feed it a > BufferedInputStream. Right now it is only set up for a java.io.Reader. > > Will that work for you? > > Bob > > > > > > On Fri, Aug 26, 2016 at 7:46 AM, Spencer Bliven > wrote: > >> I'm trying to update the way BioJava interacts with Jmol. We're currently >> loading structures into Jmol by converting them to PDB format and passing >> that string to JmolViewer.openStringInline(). Now that Jmol 14.6 is >> available in maven, we need to move away from PDB. >> >> My first choice would be to use MMTF as the exchange format. Is there a >> way to pass MMTF to Jmol? Resolver.determineAtomSetCollectionReader >> failed (probably correctly) to recognize an MMTF binary stream when >> converted to a string using the default encoding, so openStringInline() >> doesn't work. >> >> Possibly related, the mmtf demo at http://chemapps.stolaf.edu/ >> jmol/jsmol/mmtf.htm gives an unrecognized file format error for me. >> >> -Spencer >> >> >> -- >> >> ___ >> Jmol-users mailing list >> Jmol-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/jmol-users >> >> > > > -- > Robert M. Hanson > Larson-Anderson Professor of Chemistry > St. Olaf College > Northfield, MN > http://www.stolaf.edu/people/hansonr > > > If nature does not answer first what we want, > it is better to take what answer we get. > > -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900 > > > > -- > > ___ > Jmol-users mailing list > Jmol-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jmol-users > > -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Loading MMTF programmatically
Spencer, I've simplified that in what I am releasing today. You can use a byte[] or BufferedInputStream to introduce mmtf files. /** * Opens the file and creates the model set, given the reader. * * not used in Jmol * * @param fullPathName full path name or null * @param reader a Reader, byte[], or BufferedInputStream * * @return null or error message */ public String openReader(String fullPathName, Object reader) -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Loading MMTF programmatically
The call you will need to make is to this, in org.jmol.viewer.Viewer: public String loadModelFromFile(String fullPathName, String fileName, String[] fileNames, Object reader, boolean isAppend, MaphtParams, SB loadScript, SB sOptions, int tokType, boolean isConcat) { fullPathName should be just that fileName is the no-path name of the file from the fullPathName fileNames must be null isAppend = true is optional and allows you to append this model to the current set of models reader is your BufferedInputStream htPararms allows setting all sorts of options for file loading such as custom unit cell, custom space group, lattice, packing, biomolecule, etc. It's possible that loadScript should be non-null. (It's what is put in the state if a state is ever created.) sOptions will be ignored tokType must be 0 isConcat should be false Bob -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Loading MMTF programmatically
It would be totally inconvenient to treat the byte[] mmtf data as String data. You can cache the binary data as a byte array and then pass a cache:// protocol. Way better would be to pass the data as a buffered stream, but I don't think that is set up in Jmol. You have the data in what form? Full byte array? BufferedInputStream? The MMTF reader needs a javajs.api.GenericBinaryDocument. This it gets from jmol.adapter.smarter.SmarterJmolAdapter.getAtomSetCollectionFromReader. I think I can tweak viewer.loadModelFromFile to allow you to feed it a BufferedInputStream. Right now it is only set up for a java.io.Reader. Will that work for you? Bob On Fri, Aug 26, 2016 at 7:46 AM, Spencer Blivenwrote: > I'm trying to update the way BioJava interacts with Jmol. We're currently > loading structures into Jmol by converting them to PDB format and passing > that string to JmolViewer.openStringInline(). Now that Jmol 14.6 is > available in maven, we need to move away from PDB. > > My first choice would be to use MMTF as the exchange format. Is there a > way to pass MMTF to Jmol? Resolver.determineAtomSetCollectionReader > failed (probably correctly) to recognize an MMTF binary stream when > converted to a string using the default encoding, so openStringInline() > doesn't work. > > Possibly related, the mmtf demo at http://chemapps.stolaf.edu/ > jmol/jsmol/mmtf.htm gives an unrecognized file format error for me. > > -Spencer > > > -- > > ___ > Jmol-users mailing list > Jmol-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jmol-users > > -- Robert M. Hanson Larson-Anderson Professor of Chemistry St. Olaf College Northfield, MN http://www.stolaf.edu/people/hansonr If nature does not answer first what we want, it is better to take what answer we get. -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900 -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users