PageRenderTime 26ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/jmol/modelset/MeasurementData.java

https://github.com/cos/Jmol_parallelization
Java | 203 lines | 115 code | 16 blank | 72 comment | 34 complexity | 117aaf2aa7f0b00ccf70f7aa6644fd6d MD5 | raw file
  1. /* $RCSfile$
  2. * $Author: hansonr $
  3. * $Date: 2010-01-11 09:57:12 -0600 (Mon, 11 Jan 2010) $
  4. * $Revision: 12093 $
  5. *
  6. * Copyright (C) 2002-2005 The Jmol Development Team
  7. *
  8. * Contact: jmol-developers@lists.sf.net
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  23. */
  24. package org.jmol.modelset;
  25. import java.util.ArrayList;
  26. import java.util.BitSet;
  27. import java.util.List;
  28. import org.jmol.api.JmolMeasurementClient;
  29. import org.jmol.util.Point3fi;
  30. import org.jmol.viewer.Viewer;
  31. public class MeasurementData implements JmolMeasurementClient {
  32. /*
  33. * a class used to pass measurement parameters to Measures and
  34. * to generate a list of measurements from ScriptMathProcessor
  35. *
  36. */
  37. private JmolMeasurementClient client;
  38. private List<String> measurementStrings;
  39. private Atom[] atoms;
  40. public boolean mustBeConnected;
  41. public boolean mustNotBeConnected;
  42. public TickInfo tickInfo;
  43. public int tokAction;
  44. public List<Object> points;
  45. public float[] rangeMinMax;
  46. public String strFormat;
  47. public boolean isAll;
  48. private String units;
  49. /*
  50. * the general constructor. tokAction is not used here, but simply
  51. * passed back to the
  52. */
  53. public MeasurementData(List<Object> points, int tokAction,
  54. float[] rangeMinMax, String strFormat, String units,
  55. TickInfo tickInfo,
  56. boolean mustBeConnected, boolean mustNotBeConnected,
  57. boolean isAll) {
  58. this.tokAction = tokAction;
  59. this.points = points;
  60. this.rangeMinMax = rangeMinMax;
  61. this.strFormat = strFormat;
  62. this.units = units;
  63. this.tickInfo = tickInfo;
  64. this.mustBeConnected = mustBeConnected;
  65. this.mustNotBeConnected = mustNotBeConnected;
  66. this.isAll = isAll;
  67. }
  68. /**
  69. * if this is the client, then this method is
  70. * called by MeasurementData when a measurement is ready
  71. *
  72. * @param m
  73. *
  74. */
  75. public void processNextMeasure(Measurement m) {
  76. float value = m.getMeasurement();
  77. if (rangeMinMax != null && rangeMinMax[0] != Float.MAX_VALUE
  78. && (value < rangeMinMax[0] || value > rangeMinMax[1]))
  79. return;
  80. //System.out.println(Escape.escapeArray(m.getCountPlusIndices()));
  81. measurementStrings.add(m.getString(viewer, strFormat, units));
  82. }
  83. /**
  84. * if this is the client, then this method
  85. * can be called to get the result vector
  86. *
  87. * @param viewer
  88. * @return Vector of formatted Strings
  89. *
  90. */
  91. public List<String> getMeasurements(Viewer viewer) {
  92. this.viewer = viewer;
  93. measurementStrings = new ArrayList<String>();
  94. define(null, viewer.getModelSet());
  95. return measurementStrings;
  96. }
  97. private Viewer viewer;
  98. /**
  99. * called by the client to generate a set of measurements
  100. *
  101. * @param client or null to specify this to be our own client
  102. * @param modelSet
  103. */
  104. public void define(JmolMeasurementClient client, ModelSet modelSet) {
  105. this.client = (client == null ? this : client);
  106. atoms = modelSet.atoms;
  107. /*
  108. * sets up measures based on an array of atom selection expressions -RMH 3/06
  109. *
  110. *(1) run through first expression, choosing model
  111. *(2) for each item of next bs, iterate over next bitset, etc.
  112. *(3) for each last bitset, trigger toggle(int[])
  113. *
  114. *simple!
  115. *
  116. */
  117. int nPoints = points.size();
  118. if (nPoints < 2)
  119. return;
  120. int modelIndex = -1;
  121. Point3fi[] pts = new Point3fi[4];
  122. int[] indices = new int[5];
  123. Measurement m = new Measurement(modelSet, indices, pts, null);
  124. m.setCount(nPoints);
  125. int ptLastAtom = -1;
  126. for (int i = 0; i < nPoints; i++) {
  127. Object obj = points.get(i);
  128. if (obj instanceof BitSet) {
  129. BitSet bs = (BitSet) obj;
  130. int nAtoms = bs.cardinality();
  131. if (nAtoms == 0)
  132. return;
  133. if (nAtoms > 1)
  134. modelIndex = 0;
  135. ptLastAtom = i;
  136. indices[i + 1] = bs.nextSetBit(0);
  137. } else {
  138. if (pts == null)
  139. pts = new Point3fi[4];
  140. pts[i] = (Point3fi)obj;
  141. indices[i + 1] = -2 - i;
  142. }
  143. }
  144. nextMeasure(0, ptLastAtom, m, modelIndex);
  145. }
  146. /**
  147. * iterator for measurements
  148. *
  149. * @param thispt
  150. * @param ptLastAtom
  151. * @param m
  152. * @param thisModel
  153. */
  154. private void nextMeasure(int thispt, int ptLastAtom, Measurement m, int thisModel ) {
  155. if (thispt > ptLastAtom) {
  156. if (m.isValid()
  157. && (!mustBeConnected || m.isConnected(atoms, thispt))
  158. && (!mustNotBeConnected || !m.isConnected(atoms, thispt)))
  159. client.processNextMeasure(m);
  160. return;
  161. }
  162. BitSet bs = (BitSet) points.get(thispt);
  163. int[] indices = m.getCountPlusIndices();
  164. int thisAtomIndex = (thispt == 0 ? Integer.MAX_VALUE : indices[thispt]);
  165. if (thisAtomIndex < 0) {
  166. nextMeasure(thispt + 1, ptLastAtom, m, thisModel);
  167. return;
  168. }
  169. boolean haveNext = false;
  170. for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
  171. if (i == thisAtomIndex)
  172. continue;
  173. int modelIndex = atoms[i].getModelIndex();
  174. if (thisModel >= 0) {
  175. if (thispt == 0)
  176. thisModel = modelIndex;
  177. else if (thisModel != modelIndex)
  178. continue;
  179. }
  180. indices[thispt + 1] = i;
  181. haveNext = true;
  182. nextMeasure(thispt + 1, ptLastAtom, m, thisModel);
  183. }
  184. if (!haveNext)
  185. nextMeasure(thispt + 1, ptLastAtom, m, thisModel);
  186. }
  187. }