예제 #1
0
  public void testItShouldChangeItsSymbolWhenGivenAValidNewOne() {
    Molecule molecule = new DefaultMolecule();
    Atom atom = molecule.addAtom("C");

    atom.setSymbol("O");

    assertEquals("O", atom.getSymbol());
  }
예제 #2
0
  public void testItShouldReportValenceTwoForAPrimaryDoubleBondTerminal() {
    Molecule molecule = new DefaultMolecule();
    Atom c1 = molecule.addAtom("C");
    Atom c2 = molecule.addAtom("C");

    molecule.connect(c1, c2, 2);

    assertEquals(2, c1.getValence());
  }
예제 #3
0
  public void testItShouldThrowWhenSettingAnIllegalAtomLabel() {
    Molecule molecule = new DefaultMolecule();
    Atom atom = molecule.addAtom("C");

    try {
      atom.setSymbol("bailout");
      fail();
    } catch (IllegalStateException e) {
    }
  }
예제 #4
0
  public void testItShouldUpdateItsCoordinatesWhenMoved() {
    Molecule molecule = new DefaultMolecule();
    Atom atom = molecule.addAtom("C");

    atom.move(100, 100, 0);

    assertEquals(100d, atom.getX());
    assertEquals(100d, atom.getY());
    assertEquals(0d, atom.getZ());
  }
예제 #5
0
 public void calcAverageBondLength() {
   double total = 0;
   for (int i = 0; i < molecule.countBonds(); i++) {
     Bond bond = molecule.getBond(i);
     total +=
         GeometryTools.calcDistance(
             new Point2D(bond.getSource().getX(), bond.getSource().getY()),
             new Point2D(bond.getTarget().getX(), bond.getTarget().getY()));
   }
   renderer.getRendererModel().setDefaultBondLength(total / molecule.countBonds());
 }
예제 #6
0
  public void testItShouldThrowWhenIllegalRadicalIsSet() {
    Molecule molecule = new DefaultMolecule();
    Atom atom = molecule.addAtom("O");

    try {
      atom.setRadical(-1);
      fail();
    } catch (IllegalStateException ignore) {
    }

    try {
      atom.setRadical(4);
      fail();
    } catch (IllegalStateException ignore) {
    }
  }
예제 #7
0
  public Atom getClosestAtom(Point2D graphCord) {
    Atom closestAtom = null;
    double closestDistance = Double.MAX_VALUE;

    for (int i = 0; i < molecule.countAtoms(); i++) {
      Atom currentAtom = molecule.getAtom(i);
      Point2D currentPointGraph =
          realCordToGraphCord(new Point2D(currentAtom.getX(), currentAtom.getY()));
      double distance = GeometryTools.calcDistance(graphCord, currentPointGraph);

      if (distance <= renderer.getRendererModel().getAtomRadius() && distance < closestDistance) {
        closestAtom = currentAtom;
        closestDistance = distance;
      }
    }
    return closestAtom;
  }
예제 #8
0
  public Bond getClosestBond(Point2D graphCord) {
    Bond closestBond = null;
    double closestDistance = Double.MAX_VALUE;
    for (int i = 0; i < molecule.countBonds(); i++) {
      Bond currentBond = molecule.getBond(i);
      Point2D currentCenterGraph =
          realCordToGraphCord(
              new Point2D(
                  (currentBond.getSource().getX() + currentBond.getTarget().getX()) / 2,
                  (currentBond.getSource().getY() + currentBond.getTarget().getY()) / 2));

      double distance = GeometryTools.calcDistance(graphCord, currentCenterGraph);

      if (distance <= renderer.getRendererModel().getAtomRadius() && distance < closestDistance) {
        closestBond = currentBond;
        closestDistance = distance;
      }
    }

    return closestBond;
  }
예제 #9
0
  public void testItShouldReportValenceFourForAQuaternaryCarbon() {
    Molecule molecule = new DefaultMolecule();
    Atom c1 = molecule.addAtom("C");
    Atom c2 = molecule.addAtom("C");
    Atom c3 = molecule.addAtom("C");
    Atom c4 = molecule.addAtom("C");
    Atom c5 = molecule.addAtom("C");

    molecule.connect(c1, c2, 1);
    molecule.connect(c1, c3, 1);
    molecule.connect(c1, c4, 1);
    molecule.connect(c1, c5, 1);

    assertEquals(4, c1.getValence());
  }