/** Produce the secondary radius based upon the second atom radius. */
 public float getSplitBondRadius(final Bond bond) {
   final Atom atom = bond.getAtom(1);
   final StructureMap structureMap = atom.getStructure().getStructureMap();
   final StructureStyles structureStyles = structureMap.getStructureStyles();
   final AtomStyle atomStyle = (AtomStyle) structureStyles.getStyle(atom);
   return this.scale * atomStyle.getAtomRadius(atom);
 }
 /*	public void fixAtomsOfBond(){ // do fix bonds of Atom first
 	ArrayList<Atom> temp = new ArrayList<Atom>(atomList.size());
 	ArrayList<Bond> temp2 = new ArrayList<Bond>(bondList.size());
 	for(int i = 0; i < temp2.size(); i++){ // iterates bondList
 		for(int j = 0; j < atomList.size(); j++){//iterates atomlist
 			temp2 = atomList.get(j).getAdjacentBonds();
 			for(int k = 0; k < temp2.size(); k++){ //iterates bonds on atomList
 				if(temp2.get(k).getEdgeNum() == bondList.get(k).getEdgeNum()){
 					temp.set(k, bondList.get(j));
 				}
 			}
 			bondList.get(i).setAdjacentAtoms(temp);
 		}
 	}
 } */
 public String toString() {
   String temp = " ";
   if (atomList == null) {
     return "Null found for atomList";
   }
   for (Atom a : atomList) {
     temp = temp.concat(a.toString()) + "\n";
   }
   if (bondList == null) {
     return "Null found for bondList";
   }
   if (bondList.isEmpty()) {
     temp += " bondList is empty";
     // return "bondList is empty";
   }
   for (Bond b : bondList) {
     temp = temp.concat(b.toString()) + "\n";
   }
   return temp;
 }
Exemple #3
0
  @Test
  public void testSetSorting() {
    Set<String> stringHashSet = Sets.newHashSet("b", "a", "z", "g");

    Set<StringObject> stringObjectHashSet =
        Sets.newHashSet(
            new StringObject("b"),
            new StringObject("a"),
            new StringObject("z"),
            new StringObject("g"));
    Bond.obs("stringHashSet", serializer.serialize(stringHashSet))
        .obs("stringObjectHashSet", serializer.serialize(stringObjectHashSet))
        .spy("hash sets");

    Set<String> stringOnlyTreeSet = new TreeSet<>(REVERSE_SORT_COMPARATOR);
    stringOnlyTreeSet.add("b");
    stringOnlyTreeSet.add("a");
    stringOnlyTreeSet.add("z");
    stringOnlyTreeSet.add("g");
    Bond.obs("stringOnlyTreeSet", serializer.serialize(stringOnlyTreeSet)).spy("tree sets");
  }
Exemple #4
0
 @Test
 public void testBond() {
   Fragment frag = new Fragment(mock(Element.class));
   Atom a1 = new Atom(1, ChemEl.C, frag);
   Atom a2 = new Atom(2, ChemEl.C, frag);
   frag.addAtom(a1);
   frag.addAtom(a2);
   Bond bond = new Bond(a1, a2, 1);
   assertNotNull("Got bond", bond);
   assertEquals("From = 1", 1, bond.getFrom());
   assertEquals("To = 2", 2, bond.getTo());
   assertEquals("Order = 1", 1, bond.getOrder());
   assertEquals(a1, bond.getFromAtom());
   assertEquals(a2, bond.getToAtom());
   assertEquals(a2, bond.getOtherAtom(a1));
   assertEquals(a1, bond.getOtherAtom(a2));
   assertEquals(null, bond.getBondStereo());
   assertEquals(null, bond.getSmilesStereochemistry());
 }
Exemple #5
0
  @Test
  public void testMapSorting() {
    Map<String, String> stringOnlyHashMap = new HashMap<>();
    stringOnlyHashMap.put("b", "bar");
    stringOnlyHashMap.put("a", "foo");
    stringOnlyHashMap.put("z", "baz");
    stringOnlyHashMap.put("g", "test");

    Map<StringObject, String> stringObjectHashMap = new HashMap<>();
    stringObjectHashMap.put(new StringObject("b"), "bar");
    stringObjectHashMap.put(new StringObject("a"), "foo");
    stringObjectHashMap.put(new StringObject("z"), "baz");
    stringObjectHashMap.put(new StringObject("g"), "test");
    Bond.obs("stringOnlyHashMap", serializer.serialize(stringOnlyHashMap))
        .obs("stringObjectHashMap", serializer.serialize(stringObjectHashMap))
        .spy("hash maps");

    Map<String, String> stringOnlyTreeMap = new TreeMap<>(REVERSE_SORT_COMPARATOR);
    stringOnlyTreeMap.put("b", "bar");
    stringOnlyTreeMap.put("a", "foo");
    stringOnlyTreeMap.put("z", "baz");
    stringOnlyTreeMap.put("g", "test");
    Bond.obs("stringOnlyTreeMap", serializer.serialize(stringOnlyTreeMap)).spy("tree maps");
  }
Exemple #6
0
  @Test
  public void testCustomTypeAdapter() {
    serializer =
        serializer.withTypeAdapter(
            StringObject.class,
            new JsonSerializer<StringObject>() {
              @Override
              public JsonElement serialize(
                  StringObject strObj, Type type, JsonSerializationContext jsc) {
                return new JsonPrimitive(strObj.toString() + ", with custom serialization!");
              }
            });

    Bond.obs("StringObject", serializer.serialize(new StringObject("foobar"))).spy();
  }
  public void paintComponent(Graphics g) {
    clearScreen(g);
    drawGrid(g);
    drawElements(g);

    if (drawBondLine == true) {
      Bond.drawDrag(g, Color.MAGENTA, elist.getSelected(), currentX, currentY);
    }

    if (drawArrowLine == true) {
      Arrow.drawDrag(g, Color.BLUE, elist.getSelected(), currentX, currentY);
    }

    drawConnections(g);
  }
Exemple #8
0
 @Test
 public void testBondMutation() {
   Fragment frag = new Fragment(mock(Element.class));
   Atom a1 = new Atom(1, ChemEl.C, frag);
   Atom a2 = new Atom(2, ChemEl.C, frag);
   Atom a3 = new Atom(3, ChemEl.C, frag);
   Atom a4 = new Atom(4, ChemEl.C, frag);
   frag.addAtom(a1);
   frag.addAtom(a2);
   frag.addAtom(a3);
   frag.addAtom(a4);
   Bond bond = new Bond(a2, a3, 1);
   bond.setOrder(2);
   assertEquals("Order = 2", 2, bond.getOrder());
   BondStereo bondStereo = new BondStereo(new Atom[] {a1, a2, a3, a4}, BondStereoValue.TRANS);
   bond.setBondStereo(bondStereo);
   assertEquals(bondStereo, bond.getBondStereo());
   bond.setSmilesStereochemistry(SMILES_BOND_DIRECTION.LSLASH);
   assertEquals(SMILES_BOND_DIRECTION.LSLASH, bond.getSmilesStereochemistry());
 }
Exemple #9
0
  @Test
  public void testNestedSorting() {
    Set<String> stringHashSet = Sets.newHashSet("b", "a", "z", "g");
    Map<String, String> stringHashMap = new HashMap<>();
    stringHashMap.put("b", "bar");
    stringHashMap.put("a", "foo");
    stringHashMap.put("z", "baz");
    stringHashMap.put("g", "test");

    NestingObject no = new NestingObject();
    no.stringMap = stringHashMap;
    no.stringSet = stringHashSet;

    Map<String, Object> objectMap = new HashMap<>();
    objectMap.put("nestingObject", no);
    objectMap.put("hashSet", stringHashSet);
    objectMap.put("hashMap", stringHashMap);

    Set<Object> objectSet = Sets.newHashSet(stringHashSet, stringHashMap, no);

    Bond.obs("objectMap", serializer.serialize(objectMap))
        .obs("objectSet", serializer.serialize(objectSet))
        .spy();
  }
  public static void makeBonds(
      ArrayList<Atom> atomList, ArrayList<Bond> bondList, int aLoc, int bLoc) {
    Atom a = atomList.get(aLoc);
    Atom b = atomList.get(bLoc);

    if (aLoc != bLoc) {
      // rough distance
      if (getRoughDist(a, b) < maxBondLength) {
        Double dist = getDist(a, b);
        if (dist < maxBondLength) {
          boolean skip = false;
          // System.out.println(atomList.get(target).connectedTo.size());
          for (int i = 0; i < b.connectedTo.size(); i++) {
            if (b.connectedTo.get(i) == aLoc) {
              skip = true;
            }
          }
          if (!skip) {
            Bond newBond = new Bond();
            newBond.setTargets(aLoc, bLoc);

            newBond.getBondAvg(a, b);

            if (stick && dist <= newBond.getMaxDist()) {
              newBond.setStick(true);
            } else {
              newBond.setStick(false);
            }

            bondList.add(newBond);
            bondsMade++;
            b.connectedTo.add(aLoc);
            a.connectedTo.add(bLoc);
          }
        }
      }
    }
    bondsChecked++;
  }
  public void writeMeat() {

    try {
      for (int i = 0; i < aList.size(); i++) {

        w.write("{");
        w.newLine();
        Atom tempA = aList.get(i);

        w.write("\t" + "\"" + "vertexNum" + "\":" + tempA.getVertexNum() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "atomicNum" + "\":" + tempA.getAtomicNum() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "atomicWeight" + "\":" + tempA.getAtomicWeight() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "electroNeg" + "\":" + tempA.getElectroNeg() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "atomName" + "\":" + tempA.getAtomName() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "adjacentBonds" + "\": {");
        w.newLine();

        for (int z = 0; z < tempA.getAdjacentBonds().size(); z++) {
          w.write("\t\t" + "[");
          w.newLine();
          w.write(
              "\t\t\t"
                  + "\""
                  + "edgeNum"
                  + "\":"
                  + tempA.getAdjacentBonds().get(z).getEdgeNum()
                  + "\",");
          w.newLine();
          w.write(
              "\t\t\t"
                  + "\""
                  + "bondType"
                  + "\":"
                  + tempA.getAdjacentBonds().get(z).getBondType()
                  + "\",");
          w.newLine();
          w.write(
              "\t\t\t"
                  + "\""
                  + "exist"
                  + "\":"
                  + tempA.getAdjacentBonds().get(z).getExist()
                  + "\",");
          w.newLine();
          w.write("\t\t\t" + "\"" + "weight" + "\":" + tempA.getAdjacentBonds().get(z).getWeight());
          w.newLine();
          w.write("\t\t" + "]");
          w.newLine();
        }
        w.write("\t" + "}");
        w.newLine();
      }
      for (int p = 0; p < bList.size(); p++) {
        Bond tempB = bList.get(p);
        w.write("{");
        w.newLine();
        w.write("\t" + "\"" + "edgeNum" + "\":" + tempB.getEdgeNum() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "bondType" + "\":" + tempB.getBondType() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "exist" + "\":" + tempB.getExist() + "\",");
        w.newLine();
        w.write("\t" + "\"" + "weight" + tempB.getWeight() + "\":");
        w.newLine();
        w.write("\t" + "\"" + "adjacentAtoms" + "\": {");
        w.newLine();
        w.write("\t\t" + "\"" + "vertexNum" + "\":" + "\",");
        w.newLine();
        w.write("\t\t" + "\"" + "atomicNum" + "\":" + "\",");
        w.newLine();
        w.write("\t\t" + "\"" + "atomicWeight" + "\":" + "\",");
        w.newLine();
        w.write("\t\t" + "\"" + "electroNeg" + "\":" + "\",");
        w.newLine();
        w.write("\t\t" + "\"" + "atomName" + "\":" + "\",");
        w.newLine();
      }
      w.write("\t" + "}");
      w.newLine();

    } catch (IOException e) {
      System.out.println("error writing meat of file");
    }
  }
Exemple #12
0
  @Test
  public void testUseToStringSerialization() {
    serializer = serializer.withToStringSerialization(StringObject.class);

    Bond.obs("StringObject.toString()", serializer.serialize(new StringObject("foobar"))).spy();
  }
Exemple #13
0
 @Test
 public void testOverwriteOldDoublePrecision() {
   serializer = serializer.withDoublePrecision(2);
   serializer = serializer.withDoublePrecision(7);
   Bond.obs("pi", serializer.serialize(Math.PI)).spy();
 }
Exemple #14
0
 @Test
 public void testRestrictedFloatPrecision() {
   serializer = serializer.withFloatPrecision(5);
   Bond.obs("1.23456789f", serializer.serialize(1.23456789f)).spy();
 }
Exemple #15
0
 @Test
 public void testRestrictedDoublePrecision() {
   serializer = serializer.withDoublePrecision(3);
   Bond.obs("pi", serializer.serialize(Math.PI)).spy();
 }
Exemple #16
0
  public AbrahamGAValue getABGroup(ChemGraph p_chemGraph) {
    // #[ operation getGAGroup(ChemGraph)

    AbramData result_abram = new AbramData();
    Graph g = p_chemGraph.getGraph();
    HashMap oldCentralNode = (HashMap) (p_chemGraph.getCentralNode()).clone();

    // satuate radical site
    int max_radNum_molecule = ChemGraph.getMAX_RADICAL_NUM();
    int max_radNum_atom = Math.min(8, max_radNum_molecule);
    int[] idArray = new int[max_radNum_molecule];
    Atom[] atomArray = new Atom[max_radNum_molecule];
    Node[][] newnode = new Node[max_radNum_molecule][max_radNum_atom];

    int radicalSite = 0;
    Iterator iter = p_chemGraph.getNodeList();
    FreeElectron satuated = FreeElectron.make("0");
    while (iter.hasNext()) {
      Node node = (Node) iter.next();
      Atom atom = (Atom) node.getElement();
      if (atom.isRadical()) {
        radicalSite++;
        // save the old radical atom
        idArray[radicalSite - 1] = node.getID().intValue();
        atomArray[radicalSite - 1] = atom;
        // new a satuated atom and replace the old one
        Atom newAtom = new Atom(atom.getChemElement(), satuated);
        node.setElement(newAtom);
        node.updateFeElement();
      }
    }

    // add H to satuate chem graph
    Atom H = Atom.make(ChemElement.make("H"), satuated);
    Bond S = Bond.make("S");
    for (int i = 0; i < radicalSite; i++) {
      Node node = p_chemGraph.getNodeAt(idArray[i]);
      Atom atom = atomArray[i];
      int HNum = atom.getRadicalNumber();
      for (int j = 0; j < HNum; j++) {
        newnode[i][j] = g.addNode(H);
        g.addArcBetween(node, S, newnode[i][j]);
      }
      node.updateFgElement();
    }

    // find all the thermo groups
    iter = p_chemGraph.getNodeList();
    while (iter.hasNext()) {
      Node node = (Node) iter.next();
      Atom atom = (Atom) node.getElement();
      if (!(atom.getType().equals("H"))) {
        if (!atom.isRadical()) {

          p_chemGraph.resetThermoSite(node);
          AbrahamGAValue thisAbrahamValue = thermoLibrary.findAbrahamGroup(p_chemGraph);

          if (thisAbrahamValue == null) {
            System.err.println("Abraham group not found: " + node.getID());
          } else {
            // System.out.println(node.getID() + " " + thisGAValue.getName()+ "
            // "+thisGAValue.toString());

            result_abram.plus(thisAbrahamValue);
          }
        } else {
          System.err.println("Error: Radical detected after satuation!");
        }
      }
    }

    //        // find the BDE for all radical groups
    //        for (int i=0; i<radicalSite; i++) {
    //          	int id = idArray[i];
    //           	Node node = g.getNodeAt(id);
    //           	Atom old = (Atom)node.getElement();
    //           	node.setElement(atomArray[i]);
    //           	node.updateFeElement();
    //
    //            // get rid of the extra H at ith site
    //          	int HNum = atomArray[i].getRadicalNumber();
    //           	for (int j=0;j<HNum;j++) {
    //           		g.removeNode(newnode[i][j]);
    //           	}
    //           	node.updateFgElement();
    //
    //           	p_chemGraph.resetThermoSite(node);
    //           	ThermoGAValue thisGAValue = thermoLibrary.findRadicalGroup(p_chemGraph);
    //           	if (thisGAValue == null) {
    //           		System.err.println("Radical group not found: " + node.getID());
    //           	}
    //           	else {
    //           		//System.out.println(node.getID() + " radical correction: " +
    // thisGAValue.getName() + "  "+thisGAValue.toString());
    //           		result.plus(thisGAValue);
    //            }
    //
    //            //recover the satuated site for next radical site calculation
    //          	node.setElement(old);
    //          	node.updateFeElement();
    //           	for (int j=0;j<HNum;j++) {
    //           		newnode[i][j] = g.addNode(H);
    //           		g.addArcBetween(node,S,newnode[i][j]);
    //           	}
    //           	node.updateFgElement();
    //
    //         }
    //
    //         // recover the chem graph structure
    //         // recover the radical
    //         for (int i=0; i<radicalSite; i++) {
    //           	int id = idArray[i];
    //           	Node node = g.getNodeAt(id);
    //           	node.setElement(atomArray[i]);
    //           	node.updateFeElement();
    //           	int HNum = atomArray[i].getRadicalNumber();
    //         	//get rid of extra H
    //           	for (int j=0;j<HNum;j++) {
    //          	g.removeNode(newnode[i][j]);
    //           	}
    //           	node.updateFgElement();
    //         }
    //
    //         // substrate the enthalphy of H from the result
    //         int rad_number = p_chemGraph.getRadicalNumber();
    //         ThermoGAValue enthalpy_H = new ThermoGAValue(ENTHALPY_HYDROGEN * rad_number,
    // 0,0,0,0,0,0,0,0,0,0,0,null);
    //         result.minus(enthalpy_H);
    //
    //         // make the symmetric number correction to entropy
    //
    //         if (p_chemGraph.isAcyclic()){
    //			 int sigma = p_chemGraph.getSymmetryNumber();
    //	         ThermoGAValue symmtryNumberCorrection = new
    // ThermoGAValue(0,GasConstant.getCalMolK()*Math.log(sigma),0,0,0,0,0,0,0,0,0,0,null);
    //			 result.minus(symmtryNumberCorrection);
    //         }

    p_chemGraph.setCentralNode(oldCentralNode);

    return result_abram;

    // #]
  }