Esempio n. 1
1
  // ## operation writeChemkinSpecies(ReactionModel,SystemSnapshot)
  public static String writeChemkinSpecies(
      ReactionModel p_reactionModel, SystemSnapshot p_beginStatus) {
    // #[ operation writeChemkinSpecies(ReactionModel,SystemSnapshot)

    StringBuilder result = new StringBuilder();
    result.append("SPECIES\n");

    CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;

    // write inert gas
    for (Iterator iter = p_beginStatus.getInertGas(); iter.hasNext(); ) {
      String name = (String) iter.next();
      result.append('\t' + name + '\n');
    }

    // write species
    for (Iterator iter = cerm.getSpecies(); iter.hasNext(); ) {
      Species spe = (Species) iter.next();
      result.append('\t' + spe.getChemkinName() + '\n');
    }

    result.append("END\n");

    return result.toString();

    // #]
  }
Esempio n. 2
0
  // ## operation generateSpeciesStatus(ReactionModel,ArrayList,ArrayList,ArrayList)
  private LinkedHashMap generateSpeciesStatus(
      ReactionModel p_reactionModel,
      ArrayList p_speciesChemkinName,
      ArrayList p_speciesConc,
      ArrayList p_speciesFlux) {
    // #[ operation generateSpeciesStatus(ReactionModel,ArrayList,ArrayList,ArrayList)
    int size = p_speciesChemkinName.size();
    if (size != p_speciesConc.size() || size != p_speciesFlux.size())
      throw new InvalidSpeciesStatusException();
    LinkedHashMap speStatus = new LinkedHashMap();
    for (int i = 0; i < size; i++) {
      String name = (String) p_speciesChemkinName.get(i);
      int ID = parseIDFromChemkinName(name);
      Species spe = SpeciesDictionary.getInstance().getSpeciesFromID(ID);
      double conc = ((Double) p_speciesConc.get(i)).doubleValue();
      double flux = ((Double) p_speciesFlux.get(i)).doubleValue();

      System.out.println(
          String.valueOf(spe.getID())
              + '\t'
              + spe.getName()
              + '\t'
              + String.valueOf(conc)
              + '\t'
              + String.valueOf(flux));

      if (conc < 0) {
        double aTol = ReactionModelGenerator.getAtol();
        // if (Math.abs(conc) < aTol) conc = 0;
        // else throw new NegativeConcentrationException("species " + spe.getName() + " has negative
        // conc: " + String.valueOf(conc));
        if (conc < -100.0 * aTol)
          throw new NegativeConcentrationException(
              "Species " + spe.getName() + " has negative concentration: " + String.valueOf(conc));
      }

      SpeciesStatus ss = new SpeciesStatus(spe, 1, conc, flux);
      speStatus.put(spe, ss);
    }
    return speStatus;

    // #]
  }
Esempio n. 3
0
  // ## operation writeReactorInputFile(ReactionModel,ReactionTime,ReactionTime,SystemSnapshot)
  public boolean writeReactorInputFile(
      ReactionModel p_reactionModel,
      ReactionTime p_beginTime,
      ReactionTime p_endTime,
      SystemSnapshot p_beginStatus) {
    // #[ operation writeReactorInputFile(ReactionModel,ReactionTime,ReactionTime,SystemSnapshot)
    // construct "input" string
    String input = "<?xml version=\"1.0\" standalone=\"no\"?>" + "\n";

    String dir = System.getProperty("RMG.workingDirectory");
    if (!dir.endsWith("/")) dir += "/";
    String dtd = dir + "software/reactorModel/documentTypeDefinitions/reactorInput.dtd";
    input += "<!DOCTYPE reactorinput SYSTEM \"" + dtd + "\">" + "\n";

    input += "<reactorinput>" + "\n";
    input += "<header>" + "\n";
    input += "<title>Reactor Input File</title>" + "\n";
    input +=
        "<description>RMG-generated file used to call an external reactor model</description>"
            + "\n";
    input += "</header>" + "\n";
    input += "<inputvalues>" + "\n";
    input += "<integrationparameters>" + "\n";
    input += "<reactortype>" + reactorType + "</reactortype>" + "\n";
    input +=
        "<starttime units=\""
            + p_beginTime.getUnit()
            + "\">"
            + MathTool.formatDouble(p_beginTime.getTime(), 15, 6)
            + "</starttime>"
            + "\n";
    input +=
        "<endtime units=\""
            + p_endTime.getUnit()
            + "\">"
            + MathTool.formatDouble(p_endTime.getTime(), 15, 6)
            + "</endtime>"
            + "\n";
    //      input += "<starttime units=\"" + p_beginTime.unit + "\">" +
    // MathTool.formatDouble(p_beginTime.time,15,6) +  "</starttime>" + "\n";
    //      input += "<endtime units=\"" + p_endTime.unit + "\">" +
    // MathTool.formatDouble(p_endTime.time,15,6) +  "</endtime>" + "\n";
    input += "<rtol>" + rtol + "</rtol>" + "\n";
    input += "<atol>" + atol + "</atol>" + "\n";
    input += "</integrationparameters>" + "\n";
    input += "<chemistry>" + "\n";
    input += "</chemistry>" + "\n";
    input += "<systemstate>" + "\n";
    input +=
        "<temperature units=\"K\">"
            + MathTool.formatDouble(p_beginStatus.getTemperature().getK(), 15, 6)
            + "</temperature>"
            + "\n";
    input +=
        "<pressure units=\"Pa\">"
            + MathTool.formatDouble(p_beginStatus.getPressure().getPa(), 15, 6)
            + "</pressure>"
            + "\n";
    for (Iterator iter = p_beginStatus.getSpeciesStatus(); iter.hasNext(); ) {
      SpeciesStatus spcStatus = (SpeciesStatus) iter.next();
      Species thisSpecies = spcStatus.getSpecies();
      CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;
      if (cerm.containsAsReactedSpecies(thisSpecies)) {
        String spcChemkinName = thisSpecies.getChemkinName();
        double concentration = spcStatus.getConcentration();
        input +=
            "<amount units=\"molPerCm3\" speciesid=\""
                + spcChemkinName
                + "\">"
                + concentration
                + "</amount>"
                + "\n";
      }
    }
    for (Iterator iter = p_beginStatus.getInertGas(); iter.hasNext(); ) {
      String name = (String) iter.next();
      double conc = p_beginStatus.getInertGas(name);
      if (conc != 0.0)
        input +=
            "<amount units=\"molPerCm3\" speciesid=\"" + name + "\">" + conc + "</amount>" + "\n";
    }
    input += "</systemstate>" + "\n";
    input += "</inputvalues>" + "\n";
    input += "</reactorinput>" + "\n";

    // write "input" string to file
    try {
      String file = "chemkin/reactorInput.xml";
      FileWriter fw = new FileWriter(file);
      fw.write(input);
      fw.close();
      return true;
    } catch (Exception e) {
      System.out.println("Error in writing reactorInput.xml!");
      System.out.println(e.getMessage());
      return false;
    }

    // #]
  }
Esempio n. 4
0
  // ## operation writeChemkinThermo(ReactionModel)
  public static String writeChemkinThermo(ReactionModel p_reactionModel) {
    // #[ operation writeChemkinThermo(ReactionModel)
    /*
     String thermoHeader = "! neon added by pey (20/6/04) - used thermo for Ar\n";
    thermoHeader += "Ne                120186Ne  1               G  0300.00   5000.00  1000.00      1\n";
    thermoHeader += " 0.02500000E+02 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00    2\n";
    thermoHeader += "-0.07453750E+04 0.04366001E+02 0.02500000E+02 0.00000000E+00 0.00000000E+00    3\n";
    thermoHeader += " 0.00000000E+00 0.00000000E+00-0.07453750E+04 0.04366001E+02                   4\n";
    thermoHeader += "N2                121286N   2               G  0300.00   5000.00  1000.00      1\n";
    thermoHeader += " 0.02926640e+02 0.01487977e-01-0.05684761e-05 0.01009704e-08-0.06753351e-13    2\n";
    thermoHeader += "-0.09227977e+04 0.05980528e+02 0.03298677e+02 0.01408240e-01-0.03963222e-04    3\n";
    thermoHeader += " 0.05641515e-07-0.02444855e-10-0.01020900e+05 0.03950372e+02                   4\n";
    thermoHeader += "Ar                120186Ar  1               G  0300.00   5000.00  1000.00      1\n";
    thermoHeader += " 0.02500000e+02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00    2\n";
    thermoHeader += "-0.07453750e+04 0.04366001e+02 0.02500000e+02 0.00000000e+00 0.00000000e+00    3\n";
    thermoHeader += " 0.00000000e+00 0.00000000e+00-0.07453750e+04 0.04366001e+02                   4\n";
         */
    // #]
    String thermoHeader =
        "! The first four sets of polynomial coefficients (Ar, N2, Ne, He) are from         \n";
    thermoHeader +=
        "! THIRD MILLENIUM IDEAL GAS AND CONDENSED PHASE THERMOCHEMICAL DATABASE FOR     \n";
    thermoHeader +=
        "! COMBUSTION WITH UPDATES FROM ACTIVE THERMOCHENICAL TABLES                     \n";
    thermoHeader +=
        "! Authors: Alexander Burcat and Branko Ruscic                                   \n";
    thermoHeader +=
        "!                                                                               \n";
    thermoHeader +=
        "! The rest of the species are estimated by RMG (http://rmg.mit.edu/)            \n";
    // thermoHeader += "! Ar HF298=0.  REF=C.E. Moore 'Atomic Energy Levels' NSRDS-NBS 35 (1971)
    // p.211  \n";
    // thermoHeader += "! NASA Glen (former Lewis) Research Center   (1988)
    //    \n";
    thermoHeader +=
        "Ar                L 6/88Ar  1               G   200.000  6000.000 1000.        1\n";
    thermoHeader +=
        " 0.25000000E+01 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00    2\n";
    thermoHeader +=
        "-0.74537500E+03 0.43796749E+01 0.25000000E+01 0.00000000E+00 0.00000000E+00    3\n";
    thermoHeader +=
        " 0.00000000E+00 0.00000000E+00-0.74537500E+03 0.43796749E+01                   4\n";
    // thermoHeader += "! N2  HF298= 0.0 KJ  REF=TSIV  Max Lst Sq Error Cp @ 6000 K 0.29%
    //    \n";
    thermoHeader +=
        "N2                G 8/02N   2               G   200.000  6000.000 1000.        1\n";
    thermoHeader +=
        " 2.95257637E+00 1.39690040E-03-4.92631603E-07 7.86010195E-11-4.60755204E-15    2\n";
    thermoHeader +=
        "-9.23948688E+02 5.87188762E+00 3.53100528E+00-1.23660988E-04-5.02999433E-07    3\n";
    thermoHeader +=
        " 2.43530612E-09-1.40881235E-12-1.04697628E+03 2.96747038E+00                   4\n";
    // thermoHeader += "!Ne    HF298= 0.0 KJ REF=McBride, Heimel, Ehlers & Gordon
    //    \n";
    // thermoHeader += "!                'Thermodynamic Properties to 6000 K...' NASA SP-3001
    // (1963)   \n";
    thermoHeader +=
        "Ne                L10/90Ne  1               G    200.0   6000.00  1000.0       1\n";
    thermoHeader +=
        " 0.25000000E 01 0.00000000E 00 0.00000000E 00 0.00000000E 00 0.00000000E 00    2\n";
    thermoHeader +=
        "-0.74537500E 03 0.33553227E 01 0.25000000E 01 0.00000000E 00 0.00000000E 00    3\n";
    thermoHeader +=
        " 0.00000000E 00 0.00000000E 00-0.74537498E 03 0.33553227E 01                   4\n";
    // thermoHeader += "7440-59-7
    //    \n";
    // thermoHeader += "He  HF298=0.0 KJ  REF=McBride, Heimel, Ehlers & Gordon "Thermodynamic
    // Properties\n";
    // thermoHeader += "to 6000K ..." NASA SP-3001 1963.
    //    \n";
    thermoHeader +=
        "He REF ELEMENT    L10/90HE 1.   0.   0.   0.G   200.000  6000.000  B   4.00260 1\n";
    thermoHeader +=
        " 2.50000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00    2\n";
    thermoHeader +=
        "-7.45375000E+02 9.28723974E-01 2.50000000E+00 0.00000000E+00 0.00000000E+00    3\n";
    thermoHeader +=
        " 0.00000000E+00 0.00000000E+00-7.45375000E+02 9.28723974E-01 0.00000000E+00    4\n\n";

    StringBuilder result = new StringBuilder();
    result.append("THERMO ALL\n");
    result.append("   300.000  1000.000  5000.000\n");
    result.append(thermoHeader);

    CoreEdgeReactionModel cerm = (CoreEdgeReactionModel) p_reactionModel;
    for (Iterator iter = cerm.getSpecies(); iter.hasNext(); ) {
      Species spe = (Species) iter.next();

      if (spe.getNasaThermoSource() != null) {
        result.append("!" + spe.getNasaThermoSource() + "\n");
      }
      result.append(spe.getNasaThermoData() + "\n");
    }
    result.append("END\n");

    // Added by Amrit for Richard's liquid phase chemkin code 05/21/2009
    result.append("\n");

    return result.toString();

    // #]
  }
 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());
   }
 }