public static void setGenChi1(Residue res, double ang) {
    // set the residue to have the specified gen chi1 (in degrees)

    if ((!HardCodedResidueInfo.hasAminoAcidBB(res))
        || res.template.name.equalsIgnoreCase("GLY")
        || res.template.name.equalsIgnoreCase("PRO")) {
      // Glycine doesn't have a generalized chi1,
      // and we cannot freely change proline's (sidechain idealization sets
      // a chi1 for proline that should remain in place)
      return;
    }

    double curGenChi1 = getGenChi1(res);
    double genChi1Change = ang - curGenChi1;

    DihedralRotation dihRot =
        new DihedralRotation(
            res.getCoordsByAtomName("CA"), res.getCoordsByAtomName("CB"), genChi1Change);

    // now carry out the rotation on all the sidechain atoms
    // (expect CB, since it's part of the bond begin rotated around)
    int numAtoms = res.atoms.size();
    for (int atomNum = 0; atomNum < numAtoms; atomNum++) {

      String atomName = res.atoms.get(atomNum).name;

      if (SidechainIdealizer.isSidechainAtom(atomName, res)) {
        if (!(atomName.equalsIgnoreCase("CB"))) dihRot.transform(res.coords, atomNum);
      }
    }
  }
  public static void setGenChi1(Residue res, double ang) {
    // set the residue to have the specified gen chi1 (in degrees)

    if ((!HardCodedResidueInfo.hasAminoAcidBB(res))
        || !(HardCodedResidueInfo.hasNucleicAcidBB(res)) // DZ: NA BBs are fine now
        || res.template.name.equalsIgnoreCase("GLY")
        || res.template.name.equalsIgnoreCase("PRO")) {
      // Glycine doesn't have a generalized chi1,
      // and we cannot freely change proline's (sidechain idealization sets
      // a chi1 for proline that should remain in place)
      return;
    }

    double curGenChi1 = getGenChi1(res);
    double genChi1Change = ang - curGenChi1;

    double[][] keyCoords = HardCodedResidueInfo.getKeyCoords(res);
    double[] CACoords = keyCoords[1];
    double[] CBCoords = keyCoords[2];
    // pivotAtom will be CB for amino acids, N9 or N1 for nucleic acids.
    String pivotAtom =
        HardCodedResidueInfo.hasNucleicAcidBB(res)
            ? HardCodedResidueInfo.isPyrimidine(res.template.name) ? "N9" : "N1"
            : "CB";

    DihedralRotation dihRot = new DihedralRotation(CACoords, CBCoords, genChi1Change);

    // now carry out the rotation on all the sidechain atoms
    // (expect CB, since it's part of the bond begin rotated around)
    int numAtoms = res.atoms.size();
    for (int atomNum = 0; atomNum < numAtoms; atomNum++) {

      String atomName = res.atoms.get(atomNum).name;

      if (SidechainIdealizer.isSidechainAtom(atomName, res)) {
        if (!(atomName.equalsIgnoreCase(pivotAtom))) {
          dihRot.transform(res.coords, atomNum);
        }
      }
    }
  }