Example #1
0
  public static TemplateReaction makeTemplateReaction(
      Structure p_structureSp,
      Kinetics[] p_kinetics,
      ReactionTemplate p_template,
      Structure p_structure) {
    double PT = System.currentTimeMillis();
    // Look for pre-existing reaction in Template's reactionDictionaryByStructure.
    TemplateReaction reaction = p_template.getReactionFromStructure(p_structureSp);
    Global.getReacFromStruc =
        Global.getReacFromStruc + (System.currentTimeMillis() - PT) / 1000 / 60;

    if (reaction == null) {
      // Create a new reaction.
      reaction = new TemplateReaction(p_structureSp, p_kinetics, p_template);
      if (reaction.isBackward()) {
        Logger.info(
            "Created new reverse " + p_template.getName() + " reaction: " + reaction.toString());
        TemplateReaction reverse =
            reaction.generateReverseForBackwardReaction(p_structure, p_structureSp);
        if (reverse == null) return null;
        reaction.setReverseReaction(reverse);
      } else {
        Logger.info(
            "Created new forwards " + p_template.getName() + " reaction: " + reaction.toString());
        ReactionTemplate fRT = reaction.getReactionTemplate();
        ReactionTemplate rRT = null;
        if (fRT.isNeutral()) rRT = fRT;
        else rRT = fRT.getReverseReactionTemplate();
        if (rRT != null) {
          TemplateReaction reverse =
              new TemplateReaction(p_structureSp.generateReverseStructure(), p_kinetics, rRT);
          reaction.setReverseReaction(reverse);
          reverse.setReverseReaction(reaction);
          rRT.addReaction(reverse);
        }
      }
      if (!reaction.repOk()) {
        throw new InvalidTemplateReactionException();
      }

      p_template.addReaction(reaction);
    }
    Global.makeTR += (System.currentTimeMillis() - PT) / 1000 / 60;

    if (!reaction.repOk()) {
      throw new InvalidTemplateReactionException();
    }
    return reaction;
  }
Example #2
0
  // ## operation generateReverseForBackwardReaction()
  private TemplateReaction generateReverseForBackwardReaction(Structure fs, Structure fsSp) {
    // #[ operation generateReverseForBackwardReaction()
    // we need to only generate reverse reaction for backward reaction, so that we wont be stuck
    // into a self loop.
    if (!this.isBackward()) {
      return null;
    }
    ReactionTemplate fRT = getReactionTemplate();
    ReactionTemplate rRT = null;

    if (fRT.isForward()) {
      return null;
    } else if (fRT.isNeutral()) {
      rRT = fRT;
    } else if (fRT.isBackward()) {
      rRT = fRT.getReverseReactionTemplate();
    } else {
      throw new InvalidReactionTemplateDirectionException(); // Structure fs = getStructure();
    }
    LinkedList freactant = fs.getReactantList();
    LinkedList fproduct = fs.getProductList();
    Structure rs = new Structure(fproduct, freactant, -1 * this.getDirection());
    Structure rsSp = new Structure(fsSp.products, fsSp.reactants, -1 * this.getDirection());
    // If it's in the reverse ReactionTemplate.reactionDictionaryByStructure then just return that
    // one.
    TemplateReaction rr = rRT.getReactionFromStructure(rsSp);
    if (rr != null) {
      rr.setReverseReaction(this);
      return rr;
    }
    int rNum = fproduct.size();

    Kinetics[] k = rRT.findReverseRateConstant(rs);

    // If that didnt work, what to do....

    if (k == null && rRT.name.equals("R_Recombination")) {
      ChemGraph cg = ((ChemGraph) fproduct.get(0));
      Graph g = cg.getGraph();
      Node n = (Node) g.getCentralNodeAt(2);
      if (n == null) {
        cg = ((ChemGraph) fproduct.get(1));
        g = cg.getGraph();
        n = (Node) g.getCentralNodeAt(2);
      }
      g.clearCentralNode();
      g.setCentralNode(1, n);
      k = rRT.findRateConstant(rs);
    } else if (k == null && rRT.name.equals("H_Abstraction")) {
      ChemGraph cg1 = ((ChemGraph) fproduct.get(0));
      Graph g1 = cg1.getGraph();
      Node n3 = (Node) g1.getCentralNodeAt(3);
      if (n3 == null) {
        cg1 = ((ChemGraph) fproduct.get(1));
        g1 = cg1.getGraph();
        n3 = (Node) g1.getCentralNodeAt(3);
        Node n2 = (Node) g1.getCentralNodeAt(2);
        g1.clearCentralNode();
        g1.setCentralNode(1, n3);
        g1.setCentralNode(2, n2);
        ChemGraph cg2 = ((ChemGraph) fproduct.get(0));
        Graph g2 = cg2.getGraph();
        Node n1 = (Node) g2.getCentralNodeAt(1);
        g2.clearCentralNode();
        g2.setCentralNode(3, n1);
      } else {
        Node n2 = (Node) g1.getCentralNodeAt(2);
        g1.clearCentralNode();
        g1.setCentralNode(1, n3);
        g1.setCentralNode(2, n2);
        ChemGraph cg2 = ((ChemGraph) fproduct.get(1));
        Graph g2 = cg2.getGraph();
        Node n1 = (Node) g2.getCentralNodeAt(1);
        g2.clearCentralNode();
        g2.setCentralNode(3, n1);
      }
      k = rRT.findRateConstant(rs);
    }
    /*
     * Added by MRH on 27-Aug-2009 This hard-coding is necessary for rxn family templates that are labeled
     * "thermo_consistence". After the chemgraphs are mutated, the central nodes for the products are not correct
     * (see example below). These hard-coded portions are necessary for RMG to find Kinetics for the structure.
     * Example: CH4 + H CH4 1 *1 C 0 {2,S} {3,S} {4,S} {5,S} 2 *2 H 0 {1,S} 3 H 0 {1,S} 4 H 0 {1,S} 5 H 0 {1,S} H 1
     * *3 H 1 After RMG has "reactChemGraph" and "mutate" the chemgraphs of the reactants, the products would look
     * as such: prod1 1 *1 C 1 {2,S} {3,S} {4,S} 2 H 0 {1,S} 3 H 0 {1,S} 4 H 0 {1,S} prod2 1 *3 H 0 {2,S} 2 *2 H 0
     * {1,S} Assuming the reaction as written (CH4+H=CH3+H2) is endothermic at 298K, RMG will label this structure
     * as direction=-1 (backward). When attempting to find Kinetics for the backward reaction, RMG will try to match
     * the prod1 graph against the generic graphs X_H and Y_rad_birad. It cannot match Y_rad_birad (because there is
     * no *3 node) and it cannot match X_H (because there is no *2 node). Thus, a "null" Kinetics will be returned
     * from the findReverseRateConstant call. We then relabel the central nodes on prod1 and prod2 and attempt to
     * get Kinetics for this structure. I am adding the following bit of code to work with the new reaction family
     * Aaron Vandeputte is adding to RMG: "".
     */
    else if (k == null && rRT.name.equals("intra_substitutionS_isomerization")) {
      ChemGraph cg1 = ((ChemGraph) fproduct.get(0));
      Graph g1 = cg1.getGraph();
      Node n1 = (Node) g1.getCentralNodeAt(1);
      Node n2 = (Node) g1.getCentralNodeAt(2);
      Node n3 = (Node) g1.getCentralNodeAt(3);
      Node n4 = (Node) g1.getCentralNodeAt(4);
      Node n5 = (Node) g1.getCentralNodeAt(5);
      Node n6 = (Node) g1.getCentralNodeAt(6);
      Node n7 = (Node) g1.getCentralNodeAt(7);
      g1.clearCentralNode();
      g1.setCentralNode(1, n1);
      g1.setCentralNode(2, n3);
      g1.setCentralNode(3, n2);
      if (n7 != null) {
        g1.setCentralNode(7, n4);
        g1.setCentralNode(6, n5);
        g1.setCentralNode(5, n6);
        g1.setCentralNode(4, n7);
      } else if (n6 != null) {
        g1.setCentralNode(6, n4);
        g1.setCentralNode(5, n5);
        g1.setCentralNode(4, n6);
      } else if (n5 != null) {
        g1.setCentralNode(5, n4);
        g1.setCentralNode(4, n5);
      } else if (n4 != null) g1.setCentralNode(4, n4);
      k = rRT.findRateConstant(rs);
    }
    // Adding another elseif statement for Aaron Vandeputte rxn family
    // RMG expects to find *1 and *2 in the same ChemGraph (for this rxn family)
    // but will instead find *1 and *3 in the same ChemGraph (if we've reached this far)
    // Need to switch *2 and *3
    else if (k == null && (rRT.name.equals("substitutionS") || rRT.name.equals("Substitution_O"))) {
      ChemGraph cg1 = ((ChemGraph) fproduct.get(0));
      ChemGraph cg2 = ((ChemGraph) fproduct.get(1));
      Graph g1 = cg1.getGraph();
      Graph g2 = cg2.getGraph();
      Node n3 = (Node) g1.getCentralNodeAt(3);
      if (n3 == null) {
        // Switch the identities of cg1/g1 and cg2/g2
        cg1 = ((ChemGraph) fproduct.get(1));
        g1 = cg1.getGraph();
        cg2 = ((ChemGraph) fproduct.get(0));
        g2 = cg2.getGraph();
        n3 = (Node) g1.getCentralNodeAt(3);
      }
      Node n1 = (Node) g1.getCentralNodeAt(1);
      g1.clearCentralNode();
      g1.setCentralNode(2, n3);
      g1.setCentralNode(1, n1);
      Node n2 = (Node) g2.getCentralNodeAt(2);
      g2.clearCentralNode();
      g2.setCentralNode(3, n2);
      k = rRT.findRateConstant(rs);
    } else if (k == null && rRT.name.equals("intra_H_migration")) {
      ChemGraph cg = ((ChemGraph) fproduct.get(0));
      Graph g = cg.getGraph();

      // Current max is 8 identified nodes
      Node n1 = (Node) g.getCentralNodeAt(1);
      Node n2 = (Node) g.getCentralNodeAt(2);
      Node n3 = (Node) g.getCentralNodeAt(3);
      Node n4 = (Node) g.getCentralNodeAt(4);
      Node n5 = (Node) g.getCentralNodeAt(5);
      Node n6 = (Node) g.getCentralNodeAt(6);
      Node n7 = (Node) g.getCentralNodeAt(7);
      Node n8 = (Node) g.getCentralNodeAt(8);

      g.clearCentralNode();
      // Swap the locations of the central nodes 1 and 2
      g.setCentralNode(1, n2);
      g.setCentralNode(2, n1);
      // Retain the location of the central node at 3
      g.setCentralNode(3, n3);

      if (n8 != null) {
        g.setCentralNode(4, n5);
        g.setCentralNode(5, n4);
        g.setCentralNode(6, n8);
        g.setCentralNode(7, n7);
        g.setCentralNode(8, n6);
      } else if (n7 != null) {
        g.setCentralNode(4, n5);
        g.setCentralNode(5, n4);
        g.setCentralNode(6, n7);
        g.setCentralNode(7, n6);
      } else if (n6 != null) {
        g.setCentralNode(4, n5);
        g.setCentralNode(5, n4);
        g.setCentralNode(6, n6);
      } else if (n5 != null) { // Swap the locations of the central nodes 4 and 5, if node 5 exists
        g.setCentralNode(4, n5);
        g.setCentralNode(5, n4);
      } else if (n4 != null) { // if only central node 4 exists, retain that location
        g.setCentralNode(4, n4);
      }

      k = rRT.findRateConstant(rs);
      //            rr = rRT.calculateForwardRateConstant(cg, rs);
      //            if (!rr.isForward()) {
      //                String err = "Backward:"
      //                        + structure.toString()
      //                        + String.valueOf(structure
      //                                .calculateKeq(new Temperature(298, "K")))
      //                        + '\n';
      //                err = err
      //                        + "Forward:"
      //                        + rr.structure.toString()
      //                        + String.valueOf(rr.structure
      //                                .calculateKeq(new Temperature(298, "K")));
      //                throw new InvalidReactionDirectionException(err);
      //            }
      //           rr.setReverseReaction(this);
      //           rRT.addReaction(rr);
      //           return rr;

    } else if (k == null && rRT.name.equals("H_shift_cyclopentadiene")) {
      ChemGraph cg = ((ChemGraph) fproduct.get(0));
      Graph g = cg.getGraph();

      // Current max is 6 identified nodes
      Node n1 = (Node) g.getCentralNodeAt(1);
      Node n2 = (Node) g.getCentralNodeAt(2);
      Node n3 = (Node) g.getCentralNodeAt(3);
      Node n4 = (Node) g.getCentralNodeAt(4);
      Node n5 = (Node) g.getCentralNodeAt(5);
      Node n6 = (Node) g.getCentralNodeAt(6);

      g.clearCentralNode();

      // Swap the locations of the central nodes 1 to 6
      g.setCentralNode(1, n2);
      g.setCentralNode(2, n1);
      g.setCentralNode(3, n5);
      g.setCentralNode(4, n4);
      g.setCentralNode(5, n3);
      g.setCentralNode(6, n6);
      k = rRT.findRateConstant(rs);
    }
    if (k == null) {
      Logger.error(
          "Couldn't find the rate constant for reaction: "
              + rs.toChemkinString(true)
              + " with "
              + rRT.name);
      // System.exit(0);
      return null;
    }
    rr = new TemplateReaction(rsSp, k, rRT);
    if (!rr.isForward()) {
      String err =
          "Backward:"
              + structure.toString()
              + String.valueOf(structure.calculateKeq(new Temperature(298, "K")))
              + '\n';
      err =
          err
              + "Forward:"
              + rr.structure.toString()
              + String.valueOf(rr.structure.calculateKeq(new Temperature(298, "K")));
      throw new InvalidReactionDirectionException(err);
    }
    rr.setReverseReaction(this);
    rRT.addReaction(rr);
    return rr;
    // #]
  }
 public static void main(String[] args) {
   // Initialize the logger (saves to RMG.log file).
   Logger.initialize();
   initializeSystemProperties();
   try {
     ChemGraph.readForbiddenStructure();
   } catch (IOException e1) {
     System.err.println("PopulateReactions cannot locate forbiddenStructures.txt file");
     e1.printStackTrace();
   }
   ArrheniusKinetics.setAUnits("moles");
   ArrheniusKinetics.setEaUnits("kcal/mol");
   // Creating a new ReactionModelGenerator so I can set the variable temp4BestKinetics
   // and call the new readAndMakePTL and readAndMakePRL methods
   ReactionModelGenerator rmg = new ReactionModelGenerator();
   rmg.setSpeciesSeed(new LinkedHashSet());
   // Set Global.lowTemp and Global.highTemp
   // The values of the low/highTemp are not used in the function
   // (to the best of my knowledge).
   // They are necessary for the instances of additionalKinetics,
   // e.g. H2C*-CH2-CH2-CH3 -> H3C-CH2-*CH-CH3
   /*
    * 7Apr2010: The input file will now ask the user for a TemperatureModel and PressureModel (same as the RMG
    * module). The Global .lowTemperature and .highTemperature will automatically be determined
    */
   // Global.lowTemperature = new Temperature(300,"K");
   // Global.highTemperature = new Temperature(1500,"K");
   // Define variable 'speciesSet' to store the species contained in the input file
   LinkedHashSet speciesSet = new LinkedHashSet();
   // Define variable 'reactions' to store all possible rxns between the species in speciesSet
   LinkedHashSet reactions = new LinkedHashSet();
   // Define two string variables 'listOfReactions' and 'listOfSpecies'
   // These strings will hold the list of rxns (including the structure,
   // modified Arrhenius parameters, and source/comments) and the list of
   // species (including the chemkin name and graph), respectively
   String listOfReactions =
       "Arrhenius 'A' parameter has units of: "
           + ArrheniusEPKinetics.getAUnits()
           + ",cm3,s\n"
           + "Arrhenius 'n' parameter is unitless and assumes Tref = 1K\n"
           + "Arrhenius 'E' parameter has units of: "
           + ArrheniusEPKinetics.getEaUnits()
           + "\n\n";
   String listOfSpecies = "";
   // Open and read the input file
   try {
     FileReader fr_input = new FileReader(args[0]);
     BufferedReader br_input = new BufferedReader(fr_input);
     // Read in the Database field
     String line = ChemParser.readMeaningfulLine(br_input, true);
     if (line.toLowerCase().startsWith("database")) {
       RMG.extractAndSetDatabasePath(line);
     } else {
       System.err.println("PopulateReactions: Could not" + " locate the Database field");
       System.exit(0);
     }
     // Read in the first line of the input file
     // This line should hold the temperature of the system, e.g.
     // Temperature: 500 (K)
     line = ChemParser.readMeaningfulLine(br_input, true);
     /*
      * Read max atom types (if they exist)
      */
     line = rmg.readMaxAtomTypes(line, br_input);
     /*
      * Read primary thermo libraries (if they exist)
      */
     if (line.toLowerCase().startsWith("primarythermolibrary")) {
       rmg.readAndMakePTL(br_input);
     } else {
       System.err.println(
           "PopulateReactions: Could not locate the PrimaryThermoLibrary field.\n"
               + "Line read was: "
               + line);
       System.exit(0);
     }
     line = ChemParser.readMeaningfulLine(br_input, true);
     // Read primary transport library
     if (line.toLowerCase().startsWith("primarytransportlibrary"))
       rmg.readAndMakePTransL(br_input);
     else {
       System.err.println(
           "PopulateReactions: Could not locate the PrimaryTransportLibrary field.\n"
               + "Line read was: "
               + line);
       System.exit(0);
     }
     /*
      * Read the temperature model (must be of length one)
      */
     line = ChemParser.readMeaningfulLine(br_input, true);
     rmg.createTModel(line);
     if (rmg.getTempList().size() > 1) {
       System.out.println("Please list only one temperature in the TemperatureModel field.");
       System.exit(0);
     }
     // Set the user's input temperature
     LinkedList tempList = rmg.getTempList();
     systemTemp = ((ConstantTM) tempList.get(0)).getTemperature();
     rmg.setTemp4BestKinetics(systemTemp);
     /*
      * Read the pressure model (must be of length 1)
      */
     line = ChemParser.readMeaningfulLine(br_input, true);
     rmg.createPModel(line);
     if (rmg.getPressList().size() > 1) {
       System.out.println("Please list only one pressure in the PressureModel field.");
       System.exit(0);
     }
     /*
      * Read the solvation field (if present)
      */
     line = ChemParser.readMeaningfulLine(br_input, true);
     StringTokenizer st = new StringTokenizer(line);
     // The first line should start with "Solvation", otherwise do nothing and display a message to
     // the user
     if (st.nextToken().startsWith("Solvation")) {
       line = st.nextToken().toLowerCase();
       // The options for the "Solvation" field are "on" or "off" (as of 18May2009), otherwise do
       // nothing and
       // display a message to the user
       // Note: I use "Species.useInChI" because the "Species.useSolvation" updates were not yet
       // committed.
       if (line.equals("on")) {
         Species.useSolvation = true;
         // rmg.setUseDiffusion(true);
         listOfReactions += "Solution-phase chemistry!\n\n";
       } else if (line.equals("off")) {
         Species.useSolvation = false;
         // rmg.setUseDiffusion(false);
         listOfReactions += "Gas-phase chemistry.\n\n";
       } else {
         System.out.println(
             "Error in reading input.txt file:\nThe field 'Solvation' has the options 'on' or 'off'."
                 + "\nPopulateReactions does not recognize: "
                 + line);
         return;
       }
       line = ChemParser.readMeaningfulLine(br_input, true);
     }
     /*
      * Read in the species (name, concentration, adjacency list)
      */
     if (line.toLowerCase().startsWith("speciesstatus")) {
       LinkedHashMap lhm = new LinkedHashMap();
       lhm = rmg.populateInitialStatusListWithReactiveSpecies(br_input);
       speciesSet.addAll(lhm.values());
     }
     /*
      * Read in the inert gas (name, concentration)
      */
     line = ChemParser.readMeaningfulLine(br_input, true);
     if (line.toLowerCase().startsWith("bathgas")) {
       rmg.populateInitialStatusListWithInertSpecies(br_input);
     }
     /*
      * Read in the p-dep options
      */
     line = ChemParser.readMeaningfulLine(br_input, true);
     if (line.toLowerCase().startsWith("spectroscopicdata")) {
       rmg.setSpectroscopicDataMode(line);
       line = ChemParser.readMeaningfulLine(br_input, true);
       line = rmg.setPressureDependenceOptions(line, br_input);
     }
     /*
      * Read primary kinetic libraries (if they exist)
      */
     if (line.toLowerCase().startsWith("primarykineticlibrary")) {
       rmg.readAndMakePKL(br_input);
     } else {
       System.err.println(
           "PopulateReactions: Could not locate the PrimaryKineticLibrary field."
               + "Line read was: "
               + line);
       System.exit(0);
     }
     line = ChemParser.readMeaningfulLine(br_input, true);
     if (line.toLowerCase().startsWith("reactionlibrary")) {
       rmg.readAndMakeReactionLibrary(br_input);
     } else {
       System.err.println(
           "PopulateReactions: Could not locate the ReactionLibrary field."
               + "Line read was: "
               + line);
       System.exit(0);
     }
     /*
      * Read in verbosity field (if it exists)
      */
     line = ChemParser.readMeaningfulLine(br_input, true);
     if (line != null && line.toLowerCase().startsWith("verbose")) {
       StringTokenizer st2 = new StringTokenizer(line);
       String tempString = st2.nextToken();
       tempString = st2.nextToken();
       tempString = tempString.toLowerCase();
       if (tempString.equals("on") || tempString.equals("true") || tempString.equals("yes"))
         ArrheniusKinetics.setVerbose(true);
     }
     TemplateReactionGenerator rtLibrary = new TemplateReactionGenerator();
     // / THE SERVERY BIT
     ServerSocket Server = new ServerSocket(5000);
     Logger.info("TCPServer Waiting for client on port 5000");
     Logger.info("Switching to quiet mode - only WARNINGS and above will be logged...");
     Logger.setConsoleLevel(jing.rxnSys.Logger.WARNING);
     Logger.setFileLevel(jing.rxnSys.Logger.WARNING);
     while (true) {
       Socket connected = Server.accept();
       Logger.warning(
           " THE CLIENT"
               + " "
               + connected.getInetAddress()
               + ":"
               + connected.getPort()
               + " IS CONNECTED ");
       BufferedReader inFromClient =
           new BufferedReader(new InputStreamReader(connected.getInputStream()));
       inFromClient.mark(4096); // so you can reset up to 4096 characters back.
       PrintWriter outToClient = new PrintWriter(connected.getOutputStream(), true);
       try {
         listOfReactions =
             "Arrhenius 'A' parameter has units of: "
                 + ArrheniusEPKinetics.getAUnits()
                 + ",cm3,s\n"
                 + "Arrhenius 'n' parameter is unitless and assumes Tref = 1K\n"
                 + "Arrhenius 'E' parameter has units of: "
                 + ArrheniusEPKinetics.getEaUnits()
                 + "\n\n";
         listOfSpecies = "";
         // clear old things
         speciesSet.clear();
         reactions.clear();
         /*
          * Read in the species (name, concentration, adjacency list)
          */
         LinkedHashMap lhm = new LinkedHashMap();
         lhm = rmg.populateInitialStatusListWithReactiveSpecies(inFromClient);
         speciesSet.addAll(lhm.values());
         // Check Reaction Library
         ReactionLibrary RL = rmg.getReactionLibrary();
         LibraryReactionGenerator lrg1 = new LibraryReactionGenerator(RL);
         reactions = lrg1.react(speciesSet);
         if (RL != null) {
           System.out.println("Checking Reaction Library " + RL.getName() + " for reactions.");
           Iterator ReactionIter = reactions.iterator();
           while (ReactionIter.hasNext()) {
             Reaction current_reaction = (Reaction) ReactionIter.next();
             System.out.println("Library Reaction: " + current_reaction.toString());
           }
         }
         // Add all reactions found from RMG template reaction generator
         reactions.addAll(rtLibrary.react(speciesSet));
         System.out.println("FINISHED generating template reactions");
         if (!(rmg.getReactionModelEnlarger() instanceof RateBasedRME)) {
           // NOT an instance of RateBasedRME therefore assume RateBasedPDepRME and we're doing
           // pressure
           // dependence
           CoreEdgeReactionModel cerm = new CoreEdgeReactionModel(speciesSet, reactions);
           rmg.setReactionModel(cerm);
           rmg.setReactionGenerator(rtLibrary);
           ReactionSystem rs =
               new ReactionSystem(
                   (TemperatureModel) rmg.getTempList().get(0),
                   (PressureModel) rmg.getPressList().get(0),
                   rmg.getReactionModelEnlarger(),
                   new FinishController(),
                   null,
                   rmg.getPrimaryKineticLibrary(),
                   rmg.getReactionGenerator(),
                   speciesSet,
                   (InitialStatus) rmg.getInitialStatusList().get(0),
                   rmg.getReactionModel(),
                   rmg.getLibraryReactionGenerator(),
                   0,
                   "GasPhase");
           PDepNetwork.reactionModel = rmg.getReactionModel();
           PDepNetwork.reactionSystem = rs;
           // If the reaction structure is A + B = C + D, we are not concerned w/pdep
           Iterator iter = reactions.iterator();
           LinkedHashSet nonPdepReactions = new LinkedHashSet();
           while (iter.hasNext()) {
             Reaction r = (Reaction) iter.next();
             if (FastMasterEqn.isReactionPressureDependent(r)) {
               cerm.categorizeReaction(r.getStructure());
               PDepNetwork.addReactionToNetworks(r);
             } else {
               nonPdepReactions.add(r);
             }
           }
           // Run fame calculation
           PDepKineticsEstimator pDepKineticsEstimator =
               ((RateBasedPDepRME) rmg.getReactionModelEnlarger()).getPDepKineticsEstimator();
           BathGas bathGas = new BathGas(rs);
           for (int numNetworks = 0;
               numNetworks < PDepNetwork.getNetworks().size();
               ++numNetworks) {
             LinkedHashSet allSpeciesInNetwork = new LinkedHashSet();
             PDepNetwork pdepnetwork = PDepNetwork.getNetworks().get(numNetworks);
             LinkedList isomers = pdepnetwork.getIsomers();
             for (int numIsomers = 0; numIsomers < isomers.size(); ++numIsomers) {
               PDepIsomer currentIsomer = (PDepIsomer) isomers.get(numIsomers);
               if (currentIsomer.getNumSpecies() == 2)
                 pdepnetwork.makeIsomerIncluded(currentIsomer);
             }
             pDepKineticsEstimator.runPDepCalculation(pdepnetwork, rs, cerm);
             if (pdepnetwork.getNetReactions().size() > 0) {
               String formatSpeciesName = "%1$-16s\t";
               listOfReactions +=
                   "!PDepNetwork\n"
                       + "!\tdeltaEdown = "
                       + bathGas.getDeltaEdown().getAlpha()
                       + "(T / "
                       + bathGas.getDeltaEdown().getT0()
                       + ")^"
                       + bathGas.getDeltaEdown().getN()
                       + " kJ/mol\n"
                       + "!\tbathgas MW = "
                       + bathGas.getMolecularWeight()
                       + " amu\n"
                       + "!\tbathgas LJ sigma = "
                       + bathGas.getLJSigma()
                       + " meters\n"
                       + "!\tbathgas LJ epsilon = "
                       + bathGas.getLJEpsilon()
                       + " Joules\n"
                       + "!Here are the species and their thermochemistry:\n";
               LinkedList<PDepIsomer> allpdepisomers = pdepnetwork.getIsomers();
               for (int numIsomers = 0; numIsomers < allpdepisomers.size(); ++numIsomers) {
                 LinkedList species = allpdepisomers.get(numIsomers).getSpeciesList();
                 for (int numSpecies = 0; numSpecies < species.size(); ++numSpecies) {
                   Species currentSpec = (Species) species.get(numSpecies);
                   if (!allSpeciesInNetwork.contains(currentSpec)) {
                     listOfReactions +=
                         "!\t"
                             + String.format(formatSpeciesName, currentSpec.getFullName())
                             + currentSpec.getThermoData().toString()
                             + currentSpec.getThermoData().getSource()
                             + "\n";
                     allSpeciesInNetwork.add(currentSpec);
                   }
                 }
                 speciesSet.addAll(species);
               }
               String formatRxnName = "%1$-32s\t";
               listOfReactions +=
                   "!Here are the path reactions and their high-P limit kinetics:\n";
               LinkedList<PDepReaction> pathRxns = pdepnetwork.getPathReactions();
               for (int numPathRxns = 0; numPathRxns < pathRxns.size(); numPathRxns++) {
                 Kinetics[] currentKinetics = pathRxns.get(numPathRxns).getKinetics();
                 for (int numKinetics = 0; numKinetics < currentKinetics.length; ++numKinetics) {
                   listOfReactions +=
                       "!\t"
                           + String.format(
                               formatRxnName,
                               pathRxns.get(numPathRxns).getStructure().toRestartString(true))
                           + currentKinetics[numKinetics].toChemkinString(
                               pathRxns
                                   .get(numPathRxns)
                                   .calculateHrxn(new Temperature(298.0, "K")),
                               new Temperature(298.0, "K"),
                               false)
                           + "\n";
                 }
               }
               listOfReactions += "\n";
               LinkedList<PDepReaction> indivPDepRxns = pdepnetwork.getNetReactions();
               for (int numPDepRxns = 0; numPDepRxns < indivPDepRxns.size(); numPDepRxns++) {
                 listOfReactions += indivPDepRxns.get(numPDepRxns).toRestartString(systemTemp);
               }
               LinkedList<PDepReaction> nonIncludedRxns = pdepnetwork.getNonincludedReactions();
               for (int numNonRxns = 0; numNonRxns < nonIncludedRxns.size(); ++numNonRxns) {
                 listOfReactions += nonIncludedRxns.get(numNonRxns).toRestartString(systemTemp);
               }
             }
           }
           reactions = nonPdepReactions;
         }
         // Some of the reactions may be duplicates of one another
         // (e.g. H+CH4=CH3+H2 as a forward reaction and reverse reaction)
         // Create new LinkedHashSet which will store the non-duplicate rxns
         LinkedHashSet nonDuplicateRxns = new LinkedHashSet();
         int Counter = 0;
         Iterator iter_rxns = reactions.iterator();
         while (iter_rxns.hasNext()) {
           ++Counter;
           Reaction r = (Reaction) iter_rxns.next();
           // The first reaction is not a duplicate of any previous reaction
           if (Counter == 1) {
             nonDuplicateRxns.add(r);
             listOfReactions += writeOutputString(r, rtLibrary);
             speciesSet.addAll(r.getProductList());
           }
           // Check whether the current reaction (or its reverse) has the same structure
           // of any reactions already reported in the output
           else {
             Iterator iterOverNonDup = nonDuplicateRxns.iterator();
             boolean dupRxn = false;
             while (iterOverNonDup.hasNext()) {
               Reaction temp_Reaction = (Reaction) iterOverNonDup.next();
               if (r.getStructure() == temp_Reaction.getStructure()) {
                 dupRxn = true;
                 break;
               } else if (r.hasReverseReaction()) {
                 if (r.getReverseReaction().getStructure() == temp_Reaction.getStructure()) {
                   dupRxn = true;
                   break;
                 }
               }
             }
             if (!dupRxn) {
               nonDuplicateRxns.add(r);
               // If Reaction is Not a Library Reaction
               listOfReactions += writeOutputString(r, rtLibrary);
               speciesSet.addAll(r.getProductList());
             }
           }
         }
         Iterator iter_species = speciesSet.iterator();
         // Define dummy integer 'i' so our getChemGraph().toString()
         // call only returns the graph
         int i = 0;
         while (iter_species.hasNext()) {
           Species species = (Species) iter_species.next();
           listOfSpecies +=
               species.getFullName() + "\n" + species.getChemGraph().toStringWithoutH(i) + "\n";
         }
         // Write the output files
         try {
           File rxns = new File("PopRxnsOutput_rxns.txt");
           FileWriter fw_rxns = new FileWriter(rxns);
           fw_rxns.write(listOfReactions);
           fw_rxns.close();
           File spcs = new File("PopRxnsOutput_spcs.txt");
           FileWriter fw_spcs = new FileWriter(spcs);
           fw_spcs.write(listOfSpecies);
           fw_spcs.close();
         } catch (IOException e) {
           System.err.println("Could not write PopRxnsOutput*.txt files");
         }
         // Display to the user that the program was successful and also
         // inform them where the results may be located
         System.out.println(
             "Reaction population complete. "
                 + "Results are stored in PopRxnsOutput_rxns.txt and PopRxnsOutput_spcs.txt");
         // send output to client
         System.out.println("SENDING RESPONSE TO CLIENT");
         outToClient.println(listOfSpecies);
         outToClient.println(listOfReactions);
       } catch (Throwable t) {
         Logger.error("Error in PopulateReactionsServer");
         try {
           inFromClient.reset();
           Logger.error("Input:");
           while (inFromClient.ready()) {
             Logger.error(inFromClient.readLine());
           }
         } catch (IOException e) {
           Logger.error("Couldn't read input stream");
         }
         Logger.logStackTrace(t);
         outToClient.println("Error in PopulateReactionsServer");
         t.printStackTrace(outToClient);
       }
       connected.close();
       System.out.println("SOCKET CLOSED");
     }
   } catch (FileNotFoundException e) {
     System.err.println("File was not found!\n");
   } catch (IOException e) {
     System.err.println(
         "IOException: Something maybe wrong with ChemParser.readChemGraph.\n" + e.toString());
   }
 }