<commit_before>/*
 * FrequencyGroups.java 
 * created by <NAME> 11/17/08 using GATP.java as a starting point
 * This class is the frequency database analogue to GATP
 */

package jing.chem;



import java.util.*;
import jing.chemUtil.*;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class FrequencyGroups{//gmagoon 111708: removed "implements GeneralGAPP"

    private static FrequencyGroups INSTANCE = new FrequencyGroups();		//## attribute INSTANCE
    protected FrequencyDatabase freqLibrary;

    // Constructors

    //## operation FrequencyGroups()
    private FrequencyGroups() {
        initFreqLibrary();
        //#]
    }

   //gmagoon 11/17/08: based off of generateThermoData from GATP.java;
   // this function generates a list of frequencies using Franklin's code for use in pressure-dependent network calculations
      public SpectroscopicData generateFreqData(Species species) {
		
		ChemGraph p_chemGraph = species.getChemGraph();
		ThermoData p_thermoData = species.getThermoData();
				
		// Skip if species is monatomic
		if (p_chemGraph.getAtomNumber() < 2)
			return new SpectroscopicData();
		  
		LinkedList groupCount=getFreqGroup(p_chemGraph);//use database to count groups in structure
        
		double[] vibFreq = null;
        double[] hindFreq = null;
		double[] hindBarrier = null;
			
		int atoms = p_chemGraph.getAtomNumber();
		int rotor = p_chemGraph.getInternalRotor();
		int linearity = (p_chemGraph.isLinear()) ? 0 : 1;	// 0 if linear, 1 if nonlinear
		int degeneracy = getDegeneracy(groupCount);
		
		int nFreq = 3 * atoms - 5 - rotor - degeneracy - linearity;
		if (nFreq < 0) {
			System.out.println(species.getName() + "(" + Integer.toString(species.getID()) +
				") is overspecified: " +
					Integer.toString(degeneracy) + " harmonic oscillators and " +
					Integer.toString(rotor) + " internal rotors are specified, but only " +
					Integer.toString(3 * atoms - 5 - linearity) + " modes are allowed.");
			// If possible, turn off internal rotors until the number of fitted frequencies is zero
			if (nFreq + rotor >= 0) {
				System.out.println("Turning off " + Integer.toString(Math.abs(nFreq)) + 
						" internal rotors.");
				rotor += nFreq;
			}
			else {
				// Turn off functional groups until the system is underspecified
				System.out.println("Turning off functional groups to make problem underspecified.");
				while (nFreq < 0) {
					removeFunctionalGroup(groupCount);
					degeneracy = getDegeneracy(groupCount);
					nFreq = 3 * atoms - 5 - rotor - degeneracy - linearity;
				}
			}
		}
		
		//(file writing code based on code in JDASSL.java)
        File franklInput = new File("frankie/dat");
        try {
            FileWriter fw = new FileWriter(franklInput);
            fw.write(p_thermoData.getCp300()+" "+p_thermoData.getCp400()+" "+p_thermoData.getCp500()+" "+p_thermoData.getCp600()+" "+p_thermoData.getCp800()+" "+p_thermoData.getCp1000()+" "+p_thermoData.getCp1500()+"\n");
            fw.write(atoms+"\n");
            fw.write(rotor+"\n");
            fw.write(linearity+"\n");
            //print the group counts to the file for acyclic case
            if(p_chemGraph.isAcyclic()){
                for (Iterator iter = groupCount.iterator(); iter.hasNext(); ) {
                    Integer i = (Integer) iter.next();
                    fw.write(i + "\n");
		}
                fw.write(0+"\n");//write a zero for acyclic species
            }
            else{//cyclic case: print zeroes for group values instead, followed by a line with the number of hydrogens
                for (Iterator iter = groupCount.iterator(); iter.hasNext(); ) {
                    fw.write(0 + "\n");
                }
                fw.write(p_chemGraph.getHydrogenNumber()+"\n");
            }
           
                
            fw.close();

        }
        catch (IOException e) {
            System.err.println("Problem writing frequency estimation input file!");
            e.printStackTrace();
        }<commit_msg>fixing infinite loop for cyclic species<commit_after>/*
 * FrequencyGroups.java 
 * created by <NAME> 11/17/08 using GATP.java as a starting point
 * This class is the frequency database analogue to GATP
 */

package jing.chem;



import java.util.*;
import jing.chemUtil.*;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class FrequencyGroups{//gmagoon 111708: removed "implements GeneralGAPP"

    private static FrequencyGroups INSTANCE = new FrequencyGroups();		//## attribute INSTANCE
    protected FrequencyDatabase freqLibrary;

    // Constructors

    //## operation FrequencyGroups()
    private FrequencyGroups() {
        initFreqLibrary();
        //#]
    }

   //gmagoon 11/17/08: based off of generateThermoData from GATP.java;
   // this function generates a list of frequencies using Franklin's code for use in pressure-dependent network calculations
      public SpectroscopicData generateFreqData(Species species) {
		
		ChemGraph p_chemGraph = species.getChemGraph();
		ThermoData p_thermoData = species.getThermoData();
				
		// Skip if species is monatomic
		if (p_chemGraph.getAtomNumber() < 2)
			return new SpectroscopicData();
		  
		LinkedList groupCount=getFreqGroup(p_chemGraph);//use database to count groups in structure
        
		double[] vibFreq = null;
        double[] hindFreq = null;
		double[] hindBarrier = null;
			
		int atoms = p_chemGraph.getAtomNumber();
		int rotor = p_chemGraph.getInternalRotor();
		int linearity = (p_chemGraph.isLinear()) ? 0 : 1;	// 0 if linear, 1 if nonlinear
		int degeneracy = getDegeneracy(groupCount);
		
		int nFreq = 3 * atoms - 5 - rotor - degeneracy - linearity;
		if (nFreq < 0) {
			System.out.println(species.getName() + "(" + Integer.toString(species.getID()) +
				") is overspecified: " +
					Integer.toString(degeneracy) + " harmonic oscillators and " +
					Integer.toString(rotor) + " internal rotors are specified, but only " +
					Integer.toString(3 * atoms - 5 - linearity) + " modes are allowed.");
			// If possible, turn off internal rotors until the number of fitted frequencies is zero
			if (nFreq + rotor >= 0) {
				System.out.println("Turning off " + Integer.toString(Math.abs(nFreq)) + 
						" internal rotors.");
				rotor += nFreq;
			}
			else {
				// Turn off functional groups until the system is underspecified
				System.out.println("Turning off functional groups to make problem underspecified.");
				while (nFreq < 0) {
					removeFunctionalGroup(groupCount);
					degeneracy = getDegeneracy(groupCount);
					nFreq = 3 * atoms - 5 - rotor - degeneracy - linearity;
				}
			}
		}
		
		//(file writing code based on code in JDASSL.java)
        File franklInput = new File("frankie/dat");
        try {
            FileWriter fw = new FileWriter(franklInput);
            fw.write(p_thermoData.getCp300()+" "+p_thermoData.getCp400()+" "+p_thermoData.getCp500()+" "+p_thermoData.getCp600()+" "+p_thermoData.getCp800()+" "+p_thermoData.getCp1000()+" "+p_thermoData.getCp1500()+"\n");
            fw.write(atoms+"\n");
            fw.write(rotor+"\n");
            fw.write(linearity+"\n");
            //print the group counts to the file for acyclic case
            if(p_chemGraph.isAcyclic()){
                for (Iterator iter = groupCount.iterator(); iter.hasNext(); ) {
                    Integer i = (Integer) iter.next();
                    fw.write(i + "\n");
		}
                fw.write(0+"\n");//write a zero for acyclic species
            }
            else{//cyclic case: print zeroes for group values instead, followed by a line with the number of hydrogens
                for (Iterator iter = groupCount.iterator(); iter.hasNext(); ) {
                    Integer i = (Integer) iter.next();
                    fw.write(0 + "\n");
                }
                fw.write(p_chemGraph.getHydrogenNumber()+"\n");
            }
           
                
            fw.close();

        }
        catch (IOException e) {
            System.err.println("Problem writing frequency estimation input file!");
            e.printStackTrace();
        }
{'fraction_non_alphanumeric': 0.11605761218902512, 'fraction_numerical': 0.013569813117486014, 'mean_word_length': 2.6153184165232357, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5604687', 'n_tokens_mistral': 2829, 'n_tokens_neox': 2411, 'n_words': 663}