test_class.file: legacy/src/test/java/org/openscience/cdk/normalize/NormalizerTest.java
test_class.identifier: NormalizerTest
test_class.superclass: extends CDKTestCase
test_case.body: @Test
      public void testNormalize() throws Exception {
          IAtomContainer ac = new AtomContainer();
          ac.addAtom(new Atom("C"));
          ac.addAtom(new Atom("N"));
          ac.addAtom(new Atom("O"));
          ac.addAtom(new Atom("O"));
          ac.addBond(new Bond(ac.getAtom(0), ac.getAtom(1)));
          ac.addBond(new Bond(ac.getAtom(1), ac.getAtom(2), IBond.Order.DOUBLE));
          ac.addBond(new Bond(ac.getAtom(1), ac.getAtom(3), IBond.Order.DOUBLE));
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          DocumentBuilder db = dbf.newDocumentBuilder();
          Document doc = db.newDocument();
          Element set = doc.createElement("replace-set");
          doc.appendChild(set);
          Element replace = doc.createElement("replace");
          set.appendChild(replace);
          replace.appendChild(doc.createTextNode("O=N=O"));
          Element replacement = doc.createElement("replacement");
          set.appendChild(replacement);
          replacement.appendChild(doc.createTextNode("[O-][N+]=O"));
          Normalizer.normalize(ac, doc);
          Assert.assertTrue(ac.getBond(1).getOrder() == IBond.Order.SINGLE
                  ^ ac.getBond(2).getOrder() == IBond.Order.SINGLE);
      }
test_case.class_method_signature: NormalizerTest.testNormalize()
test_case.full_signature: @Test public void testNormalize()
test_case.identifier: testNormalize
test_case.invocations: addAtom addAtom addAtom addAtom addBond getAtom getAtom addBond getAtom getAtom addBond getAtom getAtom newInstance newDocumentBuilder newDocument createElement appendChild createElement appendChild appendChild createTextNode createElement appendChild appendChild createTextNode normalize assertTrue getOrder getBond getOrder getBond
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testNormalize()
focal_class.file: legacy/src/main/java/org/openscience/cdk/normalize/Normalizer.java
focal_class.identifier: Normalizer
focal_class.class_method_signature: Normalizer.normalize(IAtomContainer ac, Document doc)
focal_class.full_signature: public static boolean normalize(IAtomContainer ac, Document doc)
focal_class.identifier: normalize
focal_class.modifiers: public static
focal_class.parameters: (IAtomContainer ac, Document doc)
focal_class.return: boolean
focal_class.signature: boolean normalize(IAtomContainer ac, Document doc)
focal_method.body: public static boolean normalize(IAtomContainer ac, Document doc) throws InvalidSmilesException, CDKException {
          NodeList nl = doc.getElementsByTagName("replace-set");
          SmilesParser sp = new SmilesParser(ac.getBuilder());
          boolean change = false;
          for (int i = 0; i < nl.getLength(); i++) {
              Element child = (Element) nl.item(i);
              NodeList replaces = child.getElementsByTagName("replace");
              NodeList replacement = child.getElementsByTagName("replacement");
              String replacementstring = replacement.item(0).getFirstChild().getNodeValue();
              if (replacementstring.indexOf('\n') > -1 || replacementstring.length() < 1) {
                  replacementstring = replacement.item(0).getFirstChild().getNextSibling().getNodeValue();
              }
              IAtomContainer replacementStructure = sp.parseSmiles(replacementstring);
              for (int k = 0; k < replaces.getLength(); k++) {
                  Element replace = (Element) replaces.item(k);
                  String replacestring = replace.getFirstChild().getNodeValue();
                  if (replacestring.indexOf('\n') > -1 || replacestring.length() < 1) {
                      replacestring = replace.getFirstChild().getNextSibling().getNodeValue();
                  }
                  IAtomContainer replaceStructure = sp.parseSmiles(replacestring);
                  List<RMap> l = null;
                  UniversalIsomorphismTester universalIsomorphismTester = new UniversalIsomorphismTester();
                  while ((l = universalIsomorphismTester.getSubgraphMap(ac, replaceStructure)) != null) {
                      List<RMap> l2 = universalIsomorphismTester.makeAtomsMapOfBondsMap(l, ac, replaceStructure);
                      Iterator<RMap> bondit = l.iterator();
                      while (bondit.hasNext()) {
                          RMap rmap = bondit.next();
                          IBond acbond = ac.getBond(rmap.getId1());
                          IBond replacebond = replacementStructure.getBond(rmap.getId2());
                          acbond.setOrder(replacebond.getOrder());
                          change = true;
                      }
                      Iterator<RMap> atomit = l2.iterator();
                      while (atomit.hasNext()) {
                          RMap rmap = atomit.next();
                          IAtom acatom = ac.getAtom(rmap.getId1());
                          IAtom replaceatom = replacementStructure.getAtom(rmap.getId2());
                          acatom.setFormalCharge(replaceatom.getFormalCharge());
                          change = true;
                      }
                  }
              }
          }
          return (change);
      }
focal_method.class_method_signature: Normalizer.normalize(IAtomContainer ac, Document doc)
focal_method.full_signature: public static boolean normalize(IAtomContainer ac, Document doc)
focal_method.identifier: normalize
focal_method.invocations: getElementsByTagName getBuilder getLength item getElementsByTagName getElementsByTagName getNodeValue getFirstChild item indexOf length getNodeValue getNextSibling getFirstChild item parseSmiles getLength item getNodeValue getFirstChild indexOf length getNodeValue getNextSibling getFirstChild parseSmiles getSubgraphMap makeAtomsMapOfBondsMap iterator hasNext next getBond getId1 getBond getId2 setOrder getOrder iterator hasNext next getAtom getId1 getAtom getId2 setFormalCharge getFormalCharge
focal_method.modifiers: public static
focal_method.parameters: (IAtomContainer ac, Document doc)
focal_method.return: boolean
focal_method.signature: boolean normalize(IAtomContainer ac, Document doc)