Search in sources :

Example 1 with SelectionException

use of de.bioforscher.jstructure.model.structure.selection.SelectionException in project jstructure by JonStargaryen.

the class SecondaryStructureAnnotator method findBridges.

/**
     * Two nonoverlapping stretches of three residues each, i-1,i,i+1 and
     * j-1,j,j+1, form either a parallel or antiparallel bridge, depending on
     * which of two basic patterns is matched. We assign a bridge between
     * residues i and j if there are two H bonds characteristic of beta-
     * structure; in particular:
     * <p>
     * Parallel Bridge(i,j) =: [Hbond(i-1,j) and Hbond(j,i+1)]
     * 							or [Hbond(j-1,i) and Hbond(i,j+1)]
     * <p>
     * Antiparallel Bridge(i,j) =: [Hbond(i,j) and Hbond(j,i)]
     * 								or [Hbond(i-1,j+1) and Hbond(j-1,i+1)]
     *
     * Optimised to use the contact set
     */
private void findBridges(List<AminoAcid> residues, List<BetaBridge> bridges) {
    List<int[]> outList = new ArrayList<>();
    for (int i = 0; i < residues.size() - 1; i++) {
        for (int j = i + 1; j < residues.size(); j++) {
            AminoAcid res1 = residues.get(i);
            AminoAcid res2 = residues.get(j);
            try {
                double distance = LinearAlgebra.on(res1.getCa().getCoordinates()).distanceFast(res2.getCa().getCoordinates());
                if (distance > CA_MIN_DIST_SQUARED) {
                    continue;
                }
                // If i>j switch them over
                if (i > j) {
                    // Switch them over
                    int old = i;
                    i = j;
                    j = old;
                }
                // Only these
                if (j < i + 3) {
                    continue;
                }
                // If it's the first
                if (i == 0) {
                    continue;
                }
                if (j == 0) {
                    continue;
                }
                // If it's the last
                if (i == residues.size() - 1) {
                    continue;
                }
                if (j == residues.size() - 1) {
                    continue;
                }
                int[] thisPair = new int[] { i, j };
                outList.add(thisPair);
            } catch (NullPointerException e) {
                throw new SelectionException("missing alpha carbons for " + res1 + " or " + res2);
            }
        }
    }
    outList.sort((o1, o2) -> {
        if (o1[0] < o2[0]) {
            return -1;
        } else if (o1[0] > o2[0]) {
            return +1;
        } else {
            if (o1[1] < o2[1]) {
                return -1;
            } else if (o1[1] > o2[1]) {
                return +1;
            } else {
                return 0;
            }
        }
    });
    for (int[] p : outList) {
        int i = p[0];
        int j = p[1];
        BridgeType btype = null;
        // Now do the bonding
        if ((isBonded(residues, i - 1, j) && isBonded(residues, j, i + 1)) || (isBonded(residues, j - 1, i) && isBonded(residues, i, j + 1))) {
            btype = BridgeType.PARALLEL;
        } else if ((isBonded(residues, i, j) && isBonded(residues, j, i)) || (isBonded(residues, i - 1, j + 1) && (isBonded(residues, j - 1, i + 1)))) {
            btype = BridgeType.ANTIPARALLEL;
        }
        if (btype != null) {
            registerBridge(residues, bridges, i, j, btype);
        }
    }
}
Also used : AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) SelectionException(de.bioforscher.jstructure.model.structure.selection.SelectionException) ArrayList(java.util.ArrayList)

Example 2 with SelectionException

use of de.bioforscher.jstructure.model.structure.selection.SelectionException in project jstructure by JonStargaryen.

the class DictionaryOfProteinSecondaryStructure method findBridges.

/**
 * Two nonoverlapping stretches of three residues each, i-1,i,i+1 and
 * j-1,j,j+1, form either a parallel or antiparallel bridge, depending on
 * which of two basic patterns is matched. We assign a bridge between
 * residues i and j if there are two H bonds characteristic of beta-
 * structure; in particular:
 * <p>
 * Parallel Bridge(i,j) =: [Hbond(i-1,j) and Hbond(j,i+1)]
 * 							or [Hbond(j-1,i) and Hbond(i,j+1)]
 * <p>
 * Antiparallel Bridge(i,j) =: [Hbond(i,j) and Hbond(j,i)]
 * 								or [Hbond(i-1,j+1) and Hbond(j-1,i+1)]
 *
 * Optimised to use the contact set
 */
private void findBridges(List<AminoAcid> residues, List<BetaBridge> bridges) {
    List<int[]> outList = new ArrayList<>();
    for (int i = 0; i < residues.size() - 1; i++) {
        for (int j = i + 1; j < residues.size(); j++) {
            AminoAcid res1 = residues.get(i);
            AminoAcid res2 = residues.get(j);
            try {
                double distance = LinearAlgebra.on(res1.getCa().getCoordinates()).distanceFast(res2.getCa().getCoordinates());
                if (distance > CA_MIN_DIST_SQUARED) {
                    continue;
                }
                // If i>j switch them over
                if (i > j) {
                    // Switch them over
                    int old = i;
                    i = j;
                    j = old;
                }
                // Only these
                if (j < i + 3) {
                    continue;
                }
                // If it's the first
                if (i == 0) {
                    continue;
                }
                if (j == 0) {
                    continue;
                }
                // If it's the last
                if (i == residues.size() - 1) {
                    continue;
                }
                if (j == residues.size() - 1) {
                    continue;
                }
                int[] thisPair = new int[] { i, j };
                outList.add(thisPair);
            } catch (SelectionException e) {
                logger.debug("missing alpha carbons for {} or {}", res1, res2);
            }
        }
    }
    outList.sort((o1, o2) -> {
        if (o1[0] < o2[0]) {
            return -1;
        } else if (o1[0] > o2[0]) {
            return +1;
        } else {
            if (o1[1] < o2[1]) {
                return -1;
            } else if (o1[1] > o2[1]) {
                return +1;
            } else {
                return 0;
            }
        }
    });
    for (int[] p : outList) {
        int i = p[0];
        int j = p[1];
        BridgeType btype = null;
        // Now do the bonding
        if ((isBonded(residues, i - 1, j) && isBonded(residues, j, i + 1)) || (isBonded(residues, j - 1, i) && isBonded(residues, i, j + 1))) {
            btype = BridgeType.PARALLEL;
        } else if ((isBonded(residues, i, j) && isBonded(residues, j, i)) || (isBonded(residues, i - 1, j + 1) && (isBonded(residues, j - 1, i + 1)))) {
            btype = BridgeType.ANTIPARALLEL;
        }
        if (btype != null) {
            registerBridge(residues, bridges, i, j, btype);
        }
    }
}
Also used : AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) SelectionException(de.bioforscher.jstructure.model.structure.selection.SelectionException) ArrayList(java.util.ArrayList)

Example 3 with SelectionException

use of de.bioforscher.jstructure.model.structure.selection.SelectionException in project jstructure by JonStargaryen.

the class DictionaryOfProteinSecondaryStructure method calculateHBonds.

/**
 * Calculate the HBonds between different groups. see Creighton page 147 f
 */
private void calculateHBonds(List<AminoAcid> residues) {
    for (int i = 0; i < residues.size() - 1; i++) {
        for (int j = i + 1; j < residues.size(); j++) {
            AminoAcid res1 = residues.get(i);
            AminoAcid res2 = residues.get(j);
            try {
                double squaredDistance = LinearAlgebra.on(res1.getCa().getCoordinates()).distanceFast(res2.getCa().getCoordinates());
                if (squaredDistance > CA_MIN_DIST_SQUARED) {
                    continue;
                }
                checkAddHBond(res1, res2);
                if (j != (i + 1)) {
                    checkAddHBond(res2, res1);
                }
            } catch (SelectionException e) {
                logger.debug("missing alpha carbons for {} or {}", res1, res2);
            }
        }
    }
}
Also used : AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) SelectionException(de.bioforscher.jstructure.model.structure.selection.SelectionException)

Example 4 with SelectionException

use of de.bioforscher.jstructure.model.structure.selection.SelectionException in project jstructure by JonStargaryen.

the class SecondaryStructureAnnotator method calculateHBondEnergy.

/**
     * Calculate HBond energy of two groups in cal/mol see Creighton page 147 f
     * <p>
     * Jeffrey, George A., An introduction to hydrogen bonding, Oxford
     * University Press, 1997. categorizes hbonds with donor-acceptor distances
     * of 2.2-2.5 &aring; as "strong, mostly covalent", 2.5-3.2 &aring; as
     * "moderate, mostly electrostatic", 3.2-4.0 &aring; as "weak,
     * electrostatic". Energies are given as 40-14, 15-4, and <4 kcal/mol
     * respectively.
     * @param residuePair
     * @return the energy of this h-bond
     */
private double calculateHBondEnergy(Pair<AminoAcid, AminoAcid> residuePair) {
    AminoAcid res1 = residuePair.getLeft();
    AminoAcid res2 = residuePair.getRight();
    try {
        Atom nAtom = res1.getN();
        double[] n = nAtom.getCoordinates();
        double[] h = res1.getH().getCoordinates();
        Atom oAtom = res2.getO();
        double[] o = oAtom.getCoordinates();
        double[] c = res2.getC().getCoordinates();
        double dno = LinearAlgebra.on(o).distance(n);
        double dhc = LinearAlgebra.on(c).distance(h);
        double dho = LinearAlgebra.on(o).distance(h);
        double dnc = LinearAlgebra.on(c).distance(n);
        // there seems to be a contact!
        if ((dno < MINDIST) || (dhc < MINDIST) || (dnc < MINDIST) || (dno < MINDIST)) {
            return HBONDLOWENERGY;
        }
        double e1 = Q / dho - Q / dhc;
        double e2 = Q / dnc - Q / dno;
        double energy = e1 + e2;
        // Avoid too strong energy
        if (energy > HBONDLOWENERGY) {
            return energy;
        }
        return HBONDLOWENERGY;
    } catch (NullPointerException e) {
        throw new SelectionException("missing backbone atoms for " + residuePair);
    }
}
Also used : AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) SelectionException(de.bioforscher.jstructure.model.structure.selection.SelectionException) Atom(de.bioforscher.jstructure.model.structure.Atom)

Example 5 with SelectionException

use of de.bioforscher.jstructure.model.structure.selection.SelectionException in project jstructure by JonStargaryen.

the class SecondaryStructureAnnotator method calculateHBonds.

/**
     * Calculate the HBonds between different groups. see Creighton page 147 f
     */
private void calculateHBonds(List<AminoAcid> residues) {
    for (int i = 0; i < residues.size() - 1; i++) {
        for (int j = i + 1; j < residues.size(); j++) {
            AminoAcid res1 = residues.get(i);
            AminoAcid res2 = residues.get(j);
            try {
                double squaredDistance = LinearAlgebra.on(res1.getCa().getCoordinates()).distanceFast(res2.getCa().getCoordinates());
                if (squaredDistance > CA_MIN_DIST_SQUARED) {
                    continue;
                }
                checkAddHBond(res1, res2);
                if (j != (i + 1)) {
                    checkAddHBond(res2, res1);
                }
            } catch (NullPointerException e) {
                throw new SelectionException("missing alpha carbons for " + res1 + " or " + res2);
            }
        }
    }
}
Also used : AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) SelectionException(de.bioforscher.jstructure.model.structure.selection.SelectionException)

Aggregations

AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)6 SelectionException (de.bioforscher.jstructure.model.structure.selection.SelectionException)6 ArrayList (java.util.ArrayList)2 Atom (de.bioforscher.jstructure.model.structure.Atom)1