public static Perturbation[] generateAll(String type, Molecule m, int flexMolResNum[], int resCount){

        ArrayList<Integer> startRes = new ArrayList<Integer>();//Molecule residue numbers to start perturbations at
        int numPerts = 0;

        //Look for any sets of resCount residues in a row in flexMolResNum
        for( int a=0; a<flexMolResNum.length - resCount + 1; a++ ){
            int molResNum = flexMolResNum[a];

            boolean found = true;
            for(int b=1; b<resCount; b++){
                if(flexMolResNum[a+b] != molResNum + b)
                    found = false;
            }

            if(found){
                if( goodStart(type, molResNum, m) ){//If molResNum is a good place to start a perturbation of the given type
                    startRes.add(molResNum);
                    numPerts++;
                }
            }
        }

        Perturbation[] ans = new Perturbation[numPerts];
        int place=0;

        for(int shift=0; shift<resCount; shift++){
        //We add perturbations in order of their starting molecule residue number modulo resCount,
        //then in order of the actual molecule residue number, to minimize extra RCs from overlaps
            for(int pertNum=0; pertNum<numPerts; pertNum++){
                if( startRes.get(pertNum) % resCount == shift ){

                    int resList[] = new int[resCount];
                    for(int b=0; b<resCount; b++)
                        resList[b] = startRes.get(pertNum) + b;

                    Perturbation p = generate(type, m, resList, null);
                    p.setDefaultParams();
                    ans[place] = p;
                    place++;
                }

            }

        }



        return ans;
    }