Exemplo n.º 1
0
  public static double getDist(Atom a, Atom b) {
    double xDist = a.getPoint().x - b.getPoint().x;
    double yDist = a.getPoint().y - b.getPoint().y;

    double dist = Math.sqrt((xDist * xDist) + (yDist * yDist));
    return dist;
  }
Exemplo n.º 2
0
    public void draw() {
      sketch.send("moveto", coords);
      sketch.send("framecircle", new Atom[] {Atom.newAtom(size)});
      if (triggered) {
        sketch.send("circle", new Atom[] {Atom.newAtom(size)});
      } else if (hover) {
        sketch.send("circle", new Atom[] {Atom.newAtom(size)});

      } else if (selected) {
        sketch.send("circle", new Atom[] {Atom.newAtom(size)});
      }
    }
Exemplo n.º 3
0
 /*	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;
 }
Exemplo n.º 4
0
 private void trigger(double dist) {
   triggered = true;
   outlet(
       0,
       new Atom[] {
         Atom.newAtom(name),
         Atom.newAtom(polar[0]),
         Atom.newAtom(polar[1]),
         Atom.newAtom(size),
         Atom.newAtom(coords[0]),
         Atom.newAtom(coords[1]),
         Atom.newAtom(coords[2])
       });
 }
Exemplo n.º 5
0
  public QTFastStartRAF(FileAccessor accessor, boolean enable) throws IOException {

    input = accessor;

    if (enable) {

      String name = accessor.getName();

      boolean log;
      String fail = null;

      synchronized (tested) {
        log = !tested.contains(name);

        if (log) {

          tested.add(name);
        }
      }

      try {
        Atom ah = null;
        Atom ftypAtom = null;

        boolean gotFtyp = false;
        boolean gotMdat = false;
        boolean justCopy = false;

        while (input.getFilePointer() < input.length()) {

          ah = new Atom(input);

          // System.out.println( "got " + ah.type +", size=" + ah.size );

          if (!isValidTopLevelAtom(ah)) {
            throw new IOException("Non top level QT atom found (" + ah.type + "). File invalid?");
          }

          if (gotFtyp && !gotMdat && ah.type.equalsIgnoreCase(ATOM_MOOV)) {
            justCopy = true;
            break;
          }

          // store ftyp atom to buffer
          if (ah.type.equalsIgnoreCase(ATOM_FTYP)) {
            ftypAtom = ah;
            ftypAtom.fillBuffer(input);
            gotFtyp = true;
          } else if (ah.type.equalsIgnoreCase(ATOM_MDAT)) {
            gotMdat = true;
            input.skipBytes((int) ah.size);
          } else {
            input.skipBytes((int) ah.size);
          }
        }

        if (justCopy) {

          transparent = true;

          return;
        }

        if (ftypAtom == null) {

          throw new IOException("No FTYP atom found");
        }

        if (ah == null || !ah.type.equalsIgnoreCase(ATOM_MOOV)) {

          throw new IOException("Last QT atom was not the MOOV atom.");
        }

        input.seek(ah.offset);

        Atom moovAtom = ah;

        moovAtom.fillBuffer(input);

        if (isCompressedMoovAtom(moovAtom)) {

          throw new IOException("Compressed MOOV qt atoms are not supported");
        }

        patchMoovAtom(moovAtom);

        body_start = ftypAtom.offset + ftypAtom.size;
        body_end = moovAtom.offset;

        header = new byte[ftypAtom.buffer.length + moovAtom.buffer.length];

        System.arraycopy(ftypAtom.buffer, 0, header, 0, ftypAtom.buffer.length);
        System.arraycopy(
            moovAtom.buffer, 0, header, ftypAtom.buffer.length, moovAtom.buffer.length);

        if (accessor.length() != header.length + (body_end - body_start)) {

          throw (new IOException("Inconsistent: file size has changed"));
        }

      } catch (Throwable e) {

        // e.printStackTrace();

        fail = Debug.getNestedExceptionMessage(e);

        transparent = true;

      } finally {

        input.seek(0);

        if (log) {

          String message;

          if (fail == null) {

            message = transparent ? "Not required" : "Required";

          } else {

            message = "Failed - " + fail;
          }

          Debug.outNoStack("MOOV relocation for " + accessor.getName() + ": " + message);
        }
      }
    } else {

      transparent = true;
    }
  }
Exemplo n.º 6
0
 @Override
 public void setValue(Atom a, Atom v) {
   m_phi.setValue(a, v);
   m_variableResolver.put(a.toString(), v.toString());
 }
Exemplo n.º 7
0
  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");
    }
  }
Exemplo n.º 8
0
 public void draw() {
   sketch.send(
       "moveto",
       new Atom[] {Atom.newAtom(coords[0]), Atom.newAtom(coords[1]), Atom.newAtom(coords[2])});
   sketch.send(
       "lineto",
       new Atom[] {Atom.newAtom(origin[0]), Atom.newAtom(origin[1]), Atom.newAtom(origin[2])});
   sketch.send(
       "lineto",
       new Atom[] {
         Atom.newAtom(origin[0]), Atom.newAtom(origin[1]), Atom.newAtom(origin[2] + 0.1)
       });
   sketch.send(
       "lineto",
       new Atom[] {Atom.newAtom(coords[0]), Atom.newAtom(coords[1]), Atom.newAtom(coords[2])});
 }
Exemplo n.º 9
0
  public static double getRoughDist(Atom a, Atom b) {
    double xDist = a.getPoint().x - b.getPoint().x;
    double yDist = a.getPoint().y - b.getPoint().y;

    return xDist + yDist;
  }
Exemplo n.º 10
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;

    // #]
  }
Exemplo n.º 11
0
  public static final void pack(List fileList, String destinationFile, final JIPEngine engine)
      throws FileNotFoundException, IOException {
    InputStream ins = null;

    File outf = new File(destinationFile);
    if (!outf.isAbsolute()) outf = new File(engine.getSearchPath(), destinationFile);

    final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(outf));

    String strPath = null;
    int len = fileList.getHeight();
    for (int i = 1; i <= len; i++) {
      try {
        PrologObject path = getRealTerm(fileList.getTerm(i));
        if (!(path instanceof Atom))
          throw new JIPTypeException(JIPTypeException.ATOM_OR_STRING, path);

        strPath = ((Atom) path).getName();
        String strFileName[] = new String[1];
        String strCurDir[] = new String[1];
        ins =
            StreamManager.getStreamManager()
                .getInputStream(strPath, engine.getSearchPath(), strFileName, strCurDir);

        String file = new File(strPath).getName();
        final int nPos = file.lastIndexOf('.');
        file = new StringBuilder(file.substring(0, nPos)).append(".jip").toString();
        PrologParser parser =
            new PrologParser(
                new ParserReader(new PushbackLineNumberInputStream(ins)),
                engine.getOperatorManager(),
                engine,
                strPath);

        try {
          PrologObject term;

          while ((term = parser.parseNext()) != null) {
            out.writeObject(term);
          }

          ins.close();
          ins = null;
        } catch (IOException ex) {
          ins.close();
          ins = null;
          out.close();

          ex.printStackTrace();
          throw new JIPJVMException(ex);
        }
      } catch (FileNotFoundException ex) {
        try {
          if (ins != null) ins.close();

          out.close();

        } catch (IOException ex1) {
        }
        ;

        throw JIPExistenceException.createSourceSynkException(Atom.createAtom(strPath));
      } catch (IOException ex) {
        try {
          if (ins != null) ins.close();
        } catch (IOException ex1) {
        }

        throw new JIPJVMException(ex);
      } catch (SecurityException ex) {
        try {
          if (ins != null) ins.close();
        } catch (IOException ex1) {
        }

        throw new JIPPermissionException("access", "source_sink", Atom.createAtom(strPath));
      } catch (JIPRuntimeException ex) {
        ex.m_strFileName = strPath;

        throw ex;
      } finally {
        try {
          if (ins != null) ins.close();
        } catch (IOException ex1) {
        }
      }
    }

    out.close();
  }