From: <ha...@us...> - 2016-08-10 17:34:04
|
Revision: 21206 http://sourceforge.net/p/jmol/code/21206 Author: hansonr Date: 2016-08-10 17:34:01 +0000 (Wed, 10 Aug 2016) Log Message: ----------- PyMOL reader upgrade Modified Paths: -------------- branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PickleReader.java branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLReader.java branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLScene.java trunk/Jmol/src/org/jmol/adapter/readers/pymol/PickleReader.java trunk/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLReader.java trunk/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLScene.java Modified: branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PickleReader.java =================================================================== --- branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PickleReader.java 2016-08-10 16:23:38 UTC (rev 21205) +++ branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PickleReader.java 2016-08-10 17:34:01 UTC (rev 21206) @@ -105,8 +105,7 @@ } private int ipt = 0; - public boolean haveBinaryString; - + @SuppressWarnings("unchecked") Map<String, Object> getMap(boolean logging) throws Exception { @@ -195,8 +194,8 @@ i = binaryDoc.readIntLE(); a = new byte[i]; binaryDoc.readByteArray(a, 0, i); + //System.out.println(bytesToString(a)); push(a); - haveBinaryString = true; break; case BINUNICODE: i = binaryDoc.readIntLE(); @@ -230,8 +229,8 @@ break; case SETITEM: o = pop(); - a = (byte[]) pop(); - ((Map<String, Object>) peek()).put(bytesToString(a), o); + String s = bytesToString(pop()); + ((Map<String, Object>) peek()).put(s, o); break; case SETITEMS: mark = getMark(); @@ -244,11 +243,7 @@ map = (Map<String, Object>) o; for (i = l.size(); --i >= 0;) { o = l.get(i); - Object oo = l.get(--i); - if (AU.isAB(oo)) - map.put(bytesToString((byte[]) oo), o); - else - map.put(oo.toString(), o); + map.put(bytesToString(l.get(--i)), o); } } break; @@ -261,7 +256,7 @@ break; case INT: /// "0x88000000" for instance - String s = bytesToString(readStringAsBytes()); + s = bytesToString(readStringAsBytes()); try { push(Integer.valueOf(Integer.parseInt(s))); } catch (Exception e) { @@ -365,9 +360,9 @@ return map; } - private String bytesToString(byte[] a) { + private String bytesToString(Object o) { try { - return new String(a, "UTF-8"); + return (AU.isAB(o) ? new String((byte[]) o, "UTF-8") : o.toString()); } catch (UnsupportedEncodingException e) { return ""; } Modified: branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLReader.java =================================================================== --- branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLReader.java 2016-08-10 16:23:38 UTC (rev 21205) +++ branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLReader.java 2016-08-10 17:34:01 UTC (rev 21206) @@ -144,7 +144,7 @@ private int bondCount; - private boolean haveBinaryArrays; + private boolean haveBinaryArrays = true; @Override protected void setup(String fullPath, Map<String, Object> htParams, Object reader) { @@ -203,7 +203,6 @@ PickleReader reader = new PickleReader(binaryDoc, vwr); Map<String, Object> map = reader.getMap(logging && Logger.debuggingHigh); - haveBinaryArrays = reader.haveBinaryString; reader = null; process(map); } @@ -274,6 +273,8 @@ // create settings and uniqueSettings lists Lst<Object> settings = fixSettings(getMapList(map, "settings")); + Lst<Object> lst = listAt(settings, PyMOL.dump_binary); + haveBinaryArrays = (lst != null && floatAt(lst, 2) == 1); sceneOrder = getMapList(map, "scene_order"); haveScenes = getFrameScenes(map); Lst<Object> file = listAt(settings, PyMOL.session_file); @@ -556,8 +557,10 @@ if (ns > stateCount) stateCount = ns; int nAtoms, nBonds; + Object o = listAt(pymolObject, 6).get(1); + haveBinaryArrays = AU.isAB(o); if (haveBinaryArrays) { - nBonds = ((byte[]) listAt(pymolObject, 6).get(1)).length / 20; + nBonds = ((byte[]) o).length / 20; nAtoms = ((byte[]) listAt(pymolObject, 7).get(1)).length / 120; n += nAtoms; } else { @@ -1763,7 +1766,7 @@ } static float floatAt(Lst<Object> list, int i) { - return (list == null ? 0 : ((Number) list.get(i)).floatValue()); + return (list == null || i >= list.size() ? 0 : ((Number) list.get(i)).floatValue()); } @SuppressWarnings("unchecked") Modified: branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLScene.java =================================================================== --- branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLScene.java 2016-08-10 16:23:38 UTC (rev 21205) +++ branches/v14_6/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLScene.java 2016-08-10 17:34:01 UTC (rev 21206) @@ -754,7 +754,7 @@ @SuppressWarnings("unchecked") float globalSetting(int i) { - Lst<Object> setting = (Lst<Object>) settings.get(i); + Lst<Object> setting = PyMOLReader.listAt(settings, i); if (setting != null && setting.size() == 3) return ((Number) setting.get(2)).floatValue(); return PyMOL.getDefaultSetting(i, pymolVersion); Modified: trunk/Jmol/src/org/jmol/adapter/readers/pymol/PickleReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/pymol/PickleReader.java 2016-08-10 16:23:38 UTC (rev 21205) +++ trunk/Jmol/src/org/jmol/adapter/readers/pymol/PickleReader.java 2016-08-10 17:34:01 UTC (rev 21206) @@ -105,8 +105,7 @@ } private int ipt = 0; - public boolean haveBinaryString; - + @SuppressWarnings("unchecked") Map<String, Object> getMap(boolean logging) throws Exception { @@ -195,8 +194,8 @@ i = binaryDoc.readIntLE(); a = new byte[i]; binaryDoc.readByteArray(a, 0, i); + //System.out.println(bytesToString(a)); push(a); - haveBinaryString = true; break; case BINUNICODE: i = binaryDoc.readIntLE(); @@ -230,8 +229,8 @@ break; case SETITEM: o = pop(); - a = (byte[]) pop(); - ((Map<String, Object>) peek()).put(bytesToString(a), o); + String s = bytesToString(pop()); + ((Map<String, Object>) peek()).put(s, o); break; case SETITEMS: mark = getMark(); @@ -244,11 +243,7 @@ map = (Map<String, Object>) o; for (i = l.size(); --i >= 0;) { o = l.get(i); - Object oo = l.get(--i); - if (AU.isAB(oo)) - map.put(bytesToString((byte[]) oo), o); - else - map.put(oo.toString(), o); + map.put(bytesToString(l.get(--i)), o); } } break; @@ -261,7 +256,7 @@ break; case INT: /// "0x88000000" for instance - String s = bytesToString(readStringAsBytes()); + s = bytesToString(readStringAsBytes()); try { push(Integer.valueOf(Integer.parseInt(s))); } catch (Exception e) { @@ -365,9 +360,9 @@ return map; } - private String bytesToString(byte[] a) { + private String bytesToString(Object o) { try { - return new String(a, "UTF-8"); + return (AU.isAB(o) ? new String((byte[]) o, "UTF-8") : o.toString()); } catch (UnsupportedEncodingException e) { return ""; } Modified: trunk/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLReader.java 2016-08-10 16:23:38 UTC (rev 21205) +++ trunk/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLReader.java 2016-08-10 17:34:01 UTC (rev 21206) @@ -144,7 +144,7 @@ private int bondCount; - private boolean haveBinaryArrays; + private boolean haveBinaryArrays = true; @Override protected void setup(String fullPath, Map<String, Object> htParams, Object reader) { @@ -203,7 +203,6 @@ PickleReader reader = new PickleReader(binaryDoc, vwr); Map<String, Object> map = reader.getMap(logging && Logger.debuggingHigh); - haveBinaryArrays = reader.haveBinaryString; reader = null; process(map); } @@ -274,6 +273,8 @@ // create settings and uniqueSettings lists Lst<Object> settings = fixSettings(getMapList(map, "settings")); + Lst<Object> lst = listAt(settings, PyMOL.dump_binary); + haveBinaryArrays = (lst != null && floatAt(lst, 2) == 1); sceneOrder = getMapList(map, "scene_order"); haveScenes = getFrameScenes(map); Lst<Object> file = listAt(settings, PyMOL.session_file); @@ -556,8 +557,10 @@ if (ns > stateCount) stateCount = ns; int nAtoms, nBonds; + Object o = listAt(pymolObject, 6).get(1); + haveBinaryArrays = AU.isAB(o); if (haveBinaryArrays) { - nBonds = ((byte[]) listAt(pymolObject, 6).get(1)).length / 20; + nBonds = ((byte[]) o).length / 20; nAtoms = ((byte[]) listAt(pymolObject, 7).get(1)).length / 120; n += nAtoms; } else { @@ -1763,7 +1766,7 @@ } static float floatAt(Lst<Object> list, int i) { - return (list == null ? 0 : ((Number) list.get(i)).floatValue()); + return (list == null || i >= list.size() ? 0 : ((Number) list.get(i)).floatValue()); } @SuppressWarnings("unchecked") Modified: trunk/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLScene.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLScene.java 2016-08-10 16:23:38 UTC (rev 21205) +++ trunk/Jmol/src/org/jmol/adapter/readers/pymol/PyMOLScene.java 2016-08-10 17:34:01 UTC (rev 21206) @@ -754,7 +754,7 @@ @SuppressWarnings("unchecked") float globalSetting(int i) { - Lst<Object> setting = (Lst<Object>) settings.get(i); + Lst<Object> setting = PyMOLReader.listAt(settings, i); if (setting != null && setting.size() == 3) return ((Number) setting.get(2)).floatValue(); return PyMOL.getDefaultSetting(i, pymolVersion); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |