test_class.declarator: builder = SilentChemObjectBuilder.getInstance()
test_class.modifier: private final static
test_class.original_string: private final static IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
test_class.type: IChemObjectBuilder
test_class.var_name: builder
test_class.declarator: ifac
test_class.modifier: private
test_class.original_string: private IsotopeFactory                  ifac;
test_class.type: IsotopeFactory
test_class.var_name: ifac
test_class.file: legacy/src/test/java/org/openscience/cdk/formula/MassToFormulaToolTest.java
test_class.identifier: MassToFormulaToolTest
test_class.superclass: extends CDKTestCase
test_case.body: @Test
      public void testMass_NegativeNULL() {
  
          Assert.assertNull(new MassToFormulaTool(builder).generate(-10.0));
      }
test_case.class_method_signature: MassToFormulaToolTest.testMass_NegativeNULL()
test_case.full_signature: @Test public void testMass_NegativeNULL()
test_case.identifier: testMass_NegativeNULL
test_case.invocations: assertNull generate
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMass_NegativeNULL()
focal_class.declarator: logger = LoggingToolFactory.createLoggingTool(MassToFormulaTool.class)
focal_class.modifier: private
focal_class.original_string: private ILoggingTool          logger = LoggingToolFactory.createLoggingTool(MassToFormulaTool.class);
focal_class.type: ILoggingTool
focal_class.var_name: logger
focal_class.declarator: builder
focal_class.modifier: private
focal_class.original_string: private IChemObjectBuilder    builder;
focal_class.type: IChemObjectBuilder
focal_class.var_name: builder
focal_class.declarator: factory
focal_class.original_string: AtomTypeFactory               factory;
focal_class.type: AtomTypeFactory
focal_class.var_name: factory
focal_class.declarator: matrix_Base
focal_class.modifier: private
focal_class.original_string: private int[][]               matrix_Base;
focal_class.type: int[][]
focal_class.var_name: matrix_Base
focal_class.declarator: orderElements
focal_class.modifier: private
focal_class.original_string: private String[]              orderElements;
focal_class.type: String[]
focal_class.var_name: orderElements
focal_class.declarator: rules
focal_class.modifier: private
focal_class.original_string: private List<IRule>           rules;
focal_class.type: List<IRule>
focal_class.var_name: rules
focal_class.declarator: mfRange
focal_class.modifier: private
focal_class.original_string: private MolecularFormulaRange mfRange;
focal_class.type: MolecularFormulaRange
focal_class.var_name: mfRange
focal_class.declarator: charge
focal_class.modifier: private
focal_class.original_string: private Double                charge;
focal_class.type: Double
focal_class.var_name: charge
focal_class.declarator: tolerance
focal_class.modifier: private
focal_class.original_string: private Double                tolerance;
focal_class.type: Double
focal_class.var_name: tolerance
focal_class.file: legacy/src/main/java/org/openscience/cdk/formula/MassToFormulaTool.java
focal_class.identifier: MassToFormulaTool
focal_class.class_method_signature: MassToFormulaTool.MassToFormulaTool(IChemObjectBuilder builder)
focal_class.full_signature: public  MassToFormulaTool(IChemObjectBuilder builder)
focal_class.identifier: MassToFormulaTool
focal_class.modifiers: public
focal_class.parameters: (IChemObjectBuilder builder)
focal_class.signature:  MassToFormulaTool(IChemObjectBuilder builder)
focal_class.class_method_signature: MassToFormulaTool.setRestrictions(List<IRule> rulesNew)
focal_class.full_signature: public void setRestrictions(List<IRule> rulesNew)
focal_class.identifier: setRestrictions
focal_class.modifiers: public
focal_class.parameters: (List<IRule> rulesNew)
focal_class.return: void
focal_class.signature: void setRestrictions(List<IRule> rulesNew)
focal_class.class_method_signature: MassToFormulaTool.getRestrictions()
focal_class.full_signature: public List<IRule> getRestrictions()
focal_class.identifier: getRestrictions
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: List<IRule>
focal_class.signature: List<IRule> getRestrictions()
focal_class.class_method_signature: MassToFormulaTool.setDefaultRestrictions()
focal_class.full_signature: public void setDefaultRestrictions()
focal_class.identifier: setDefaultRestrictions
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void setDefaultRestrictions()
focal_class.class_method_signature: MassToFormulaTool.callDefaultRestrictions()
focal_class.full_signature: private void callDefaultRestrictions()
focal_class.identifier: callDefaultRestrictions
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void callDefaultRestrictions()
focal_class.class_method_signature: MassToFormulaTool.generate(double mass)
focal_class.full_signature: public IMolecularFormulaSet generate(double mass)
focal_class.identifier: generate
focal_class.modifiers: public
focal_class.parameters: (double mass)
focal_class.return: IMolecularFormulaSet
focal_class.signature: IMolecularFormulaSet generate(double mass)
focal_class.class_method_signature: MassToFormulaTool.orderList(List<IIsotope> isotopes_TO)
focal_class.full_signature: private List<IIsotope> orderList(List<IIsotope> isotopes_TO)
focal_class.identifier: orderList
focal_class.modifiers: private
focal_class.parameters: (List<IIsotope> isotopes_TO)
focal_class.return: List<IIsotope>
focal_class.signature: List<IIsotope> orderList(List<IIsotope> isotopes_TO)
focal_class.class_method_signature: MassToFormulaTool.generateOrderE()
focal_class.full_signature: private String[] generateOrderE()
focal_class.identifier: generateOrderE
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: String[]
focal_class.signature: String[] generateOrderE()
focal_class.class_method_signature: MassToFormulaTool.getMaxOccurence(double massTo, int element_pos, int[] matrix, List<IIsotope> isoToCond_new)
focal_class.full_signature: private int getMaxOccurence(double massTo, int element_pos, int[] matrix, List<IIsotope> isoToCond_new)
focal_class.identifier: getMaxOccurence
focal_class.modifiers: private
focal_class.parameters: (double massTo, int element_pos, int[] matrix, List<IIsotope> isoToCond_new)
focal_class.return: int
focal_class.signature: int getMaxOccurence(double massTo, int element_pos, int[] matrix, List<IIsotope> isoToCond_new)
focal_class.class_method_signature: MassToFormulaTool.getFormula(List<IIsotope> isoToCond_new, int[] value_In)
focal_class.full_signature: private IMolecularFormula getFormula(List<IIsotope> isoToCond_new, int[] value_In)
focal_class.identifier: getFormula
focal_class.modifiers: private
focal_class.parameters: (List<IIsotope> isoToCond_new, int[] value_In)
focal_class.return: IMolecularFormula
focal_class.signature: IMolecularFormula getFormula(List<IIsotope> isoToCond_new, int[] value_In)
focal_class.class_method_signature: MassToFormulaTool.putInOrder(IMolecularFormula formula)
focal_class.full_signature: private IMolecularFormula putInOrder(IMolecularFormula formula)
focal_class.identifier: putInOrder
focal_class.modifiers: private
focal_class.parameters: (IMolecularFormula formula)
focal_class.return: IMolecularFormula
focal_class.signature: IMolecularFormula putInOrder(IMolecularFormula formula)
focal_class.class_method_signature: MassToFormulaTool.calculateMassT(List<IIsotope> isoToCond_new, int[] value_In)
focal_class.full_signature: private double calculateMassT(List<IIsotope> isoToCond_new, int[] value_In)
focal_class.identifier: calculateMassT
focal_class.modifiers: private
focal_class.parameters: (List<IIsotope> isoToCond_new, int[] value_In)
focal_class.return: double
focal_class.signature: double calculateMassT(List<IIsotope> isoToCond_new, int[] value_In)
focal_class.class_method_signature: MassToFormulaTool.returnOrdered(double mass, IMolecularFormulaSet formulaSet)
focal_class.full_signature: private IMolecularFormulaSet returnOrdered(double mass, IMolecularFormulaSet formulaSet)
focal_class.identifier: returnOrdered
focal_class.modifiers: private
focal_class.parameters: (double mass, IMolecularFormulaSet formulaSet)
focal_class.return: IMolecularFormulaSet
focal_class.signature: IMolecularFormulaSet returnOrdered(double mass, IMolecularFormulaSet formulaSet)
focal_class.class_method_signature: MassToFormulaTool.getMatrix(int size)
focal_class.full_signature: private int[][] getMatrix(int size)
focal_class.identifier: getMatrix
focal_class.modifiers: private
focal_class.parameters: (int size)
focal_class.return: int[][]
focal_class.signature: int[][] getMatrix(int size)
focal_method.body: public IMolecularFormulaSet generate(double mass) {
  
          if (mass <= 0.0) {
              logger.error("Proposed mass is not valid: ", mass);
              return null;
          }
          IMolecularFormula minimalMF = MolecularFormulaRangeManipulator.getMinimalFormula(mfRange, builder);
          IMolecularFormula maximalMF = MolecularFormulaRangeManipulator.getMaximalFormula(mfRange, builder);
          double massMim = MolecularFormulaManipulator.getTotalExactMass(minimalMF) - tolerance;
          double massMap = MolecularFormulaManipulator.getTotalExactMass(maximalMF) + tolerance;
          if (massMim > mass || massMap < mass) {
              logger.error("Proposed mass is out of the range: ", mass);
              return null;
          }
  
          IMolecularFormulaSet molecularFormulaSet = builder.newInstance(IMolecularFormulaSet.class);
  
          int[][] matrix = this.matrix_Base;
          int numberElements = mfRange.getIsotopeCount();
  
          // put IIsotope into a list
          List<IIsotope> isotopes_TO = new ArrayList<IIsotope>();
          Iterator<IIsotope> isIt = mfRange.isotopes().iterator();
          while (isIt.hasNext())
              isotopes_TO.add(isIt.next());
  
          isotopes_TO = orderList(isotopes_TO);
  
          for (int i = 0; i < matrix.length; i++) {
  
              /* constructing initial combinations */
              int[] value_In = new int[numberElements];
              for (int j = 0; j < numberElements; j++) {
                  if (matrix[i][j] == 0)
                      value_In[j] = 0;
                  else
                      value_In[j] = 1;
              }
  
              /* find number of element to combine */
              int count_E = 0;
              ArrayList<Integer> elem_Pos = new ArrayList<Integer>();
              for (int j = 0; j < matrix[1].length; j++)
                  if (value_In[j] != 0) {
                      count_E++;
                      elem_Pos.add(j);
                  }
  
              boolean flag = true;
              /* first position those first starting at the left */
              int possChan = 0;
              String lastMFString = "";
              while (flag) {
  
                  //				// print all combinations --------------------------------------------------
                  //				System.out.print(elem_Pos.get(possChan).intValue()+">");
                  //				for(int j= 0 ; j< matrix[1].length; j++)
                  //					System.out.print(isotopes_TO.get(j).getSymbol()+value_In[j]+"-");
                  //				System.out.println();
                  //				// print all combinations --------------------------------------------------
  
                  // control if some of the element is contained. E.g. C(1-3)H(1-3)
                  // the matrix 01 or 10 can not exist
                  boolean flagBreak = false;
                  for (int j = 0; j < matrix[1].length; j++) {
                      int min = mfRange.getIsotopeCountMin(isotopes_TO.get(j));
                      if (value_In[j] == 0) if (min != 0) flagBreak = true;
                  }
                  if (flagBreak) break;
  
                  /*
                   * Find max occurence given a mass for a element with minimal
                   * elements
                   */
                  int occurence = getMaxOccurence(mass, elem_Pos.get(possChan).intValue(), value_In, isotopes_TO);
  
                  /* at least one */
                  if (occurence == 0) break;
  
                  int maxx = mfRange.getIsotopeCountMax(isotopes_TO.get(elem_Pos.get(possChan).intValue()));
                  int minn = mfRange.getIsotopeCountMin(isotopes_TO.get(elem_Pos.get(possChan).intValue()));
  
                  /* restriction of the number of max and min number for a element */
                  if (occurence < minn | maxx < occurence) {
                      /*
                       * when is not in the occurrence that means that we have to
                       * restart one value to the predecessor.
                       */
  
                      if (possChan < elem_Pos.size() - 1) {
                          /* Means that is possible to fit the next */
                          if (maxx < occurence) value_In[elem_Pos.get(possChan).intValue()] = maxx;
                          possChan++;
  
                      } else {
                          boolean foundZ = false;
                          for (int z = possChan - 1; z >= 0; z--) {
                              if (value_In[elem_Pos.get(z).intValue()] != 1) {
                                  possChan = z;
                                  foundZ = true;
                                  int newValue = value_In[elem_Pos.get(possChan).intValue()] - 1;
  
                                  value_In[elem_Pos.get(possChan).intValue()] = newValue;
                                  for (int j = possChan + 1; j < elem_Pos.size(); j++) {
                                      int p = elem_Pos.get(j).intValue();
                                      value_In[p] = 1;
                                  }
                                  possChan++;
                                  break;
                              }
                          }
                          if (!foundZ) break;
  
                      }
  
                      continue;
                  } /* final not occurrence */
  
                  /* set the occurrence into the matrix */
                  value_In[elem_Pos.get(possChan).intValue()] = occurence;
  
                  double massT = calculateMassT(isotopes_TO, value_In);
                  double diff_new = Math.abs(mass - (massT));
  
                  if (diff_new < tolerance) {
                      IMolecularFormula myMF = getFormula(isotopes_TO, value_In);
                      String newMFString = MolecularFormulaManipulator.getString(myMF);
  
                      if (!newMFString.equals(lastMFString)) {
                          molecularFormulaSet.addMolecularFormula(myMF);
                          lastMFString = newMFString;
                      }
                  }
  
                  if (count_E == 1) /* only valid for the first random 1000 */
                  break;
  
                  if (possChan < elem_Pos.size() - 1) {
                      /* Means that is possible to fit the next */
                      //					value_In[elem_Pos.get(possChan).intValue()] = maxx;
                      possChan++;
  
                  } else {
                      boolean foundZ = false;
                      for (int z = possChan - 1; z >= 0; z--) {
                          if (value_In[elem_Pos.get(z).intValue()] != 1) {
                              possChan = z;
                              foundZ = true;
                              int newValue = value_In[elem_Pos.get(possChan).intValue()] - 1;
  
                              value_In[elem_Pos.get(possChan).intValue()] = newValue;
                              for (int j = possChan + 1; j < elem_Pos.size(); j++) {
                                  int p = elem_Pos.get(j).intValue();
                                  value_In[p] = 1;
                              }
                              possChan++;
                              break;
                          }
                      }
                      if (!foundZ) break;
  
                  }
              }
  
          }
  
          return returnOrdered(mass, molecularFormulaSet);
      }
focal_method.class_method_signature: MassToFormulaTool.generate(double mass)
focal_method.full_signature: public IMolecularFormulaSet generate(double mass)
focal_method.identifier: generate
focal_method.invocations: error getMinimalFormula getMaximalFormula getTotalExactMass getTotalExactMass error newInstance getIsotopeCount iterator isotopes hasNext add next orderList add getIsotopeCountMin get getMaxOccurence intValue get getIsotopeCountMax get intValue get getIsotopeCountMin get intValue get size intValue get intValue get intValue get intValue get size intValue get intValue get calculateMassT abs getFormula getString equals addMolecularFormula size intValue get intValue get intValue get size intValue get returnOrdered
focal_method.modifiers: public
focal_method.parameters: (double mass)
focal_method.return: IMolecularFormulaSet
focal_method.signature: IMolecularFormulaSet generate(double mass)