Search in sources :

Example 1 with Atom

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

the class OrientationsOfProteinsInMembranesAnnotator method processInternally.

@Override
protected void processInternally(Protein protein) {
    try {
        Document document = getDocument(SEARCH_URL + protein.getPdbId().getPdbId());
        if (document.text().contains("No matches")) {
            throw new ComputationException("did not find OPM entry for " + protein.getIdentifier() + " - possibly it is no membrane protein");
        }
        // create global membrane object - 3rd link points to download
        String downloadLink = document.getElementById("caption").getElementsByTag("a").get(2).attr("href");
        try (InputStreamReader inputStreamReader = new InputStreamReader(new URL(BASE_URL + downloadLink).openStream())) {
            try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
                byte[] bytes = bufferedReader.lines().collect(Collectors.joining(System.lineSeparator())).getBytes();
                // parse protein
                Protein opmProtein = ProteinParser.source(new ByteArrayInputStream(bytes)).forceProteinName(ProteinIdentifier.createFromPdbId(downloadLink.split("=")[0].split("/")[1].substring(0, 4))).parse();
                Membrane membrane = new Membrane(this);
                // superimpose opm protein onto instance of the original protein
                //TODO this alignment is by no means perfect, but works for a first glance
                SVDSuperimposer.ALPHA_CARBON_SVD_INSTANCE.align(protein.select().aminoAcids().asGroupContainer(), opmProtein.select().aminoAcids().asGroupContainer()).transform(opmProtein);
                // extract dummy atoms and move them to membrane object
                List<double[]> membraneAtoms = opmProtein.atoms().map(Atom::getParentGroup).filter(group -> group.getThreeLetterCode().equals("DUM")).flatMap(Group::atoms).map(Atom::getCoordinates).collect(Collectors.toList());
                membrane.setMembraneAtoms(membraneAtoms);
                // extract general information - that is the first table
                Element generalDataTable = document.getElementsByClass("data").get(0);
                Element thicknessTr = generalDataTable.getElementsByTag("tr").get(1);
                membrane.setHydrophobicThickness(thicknessTr.getElementsByTag("td").get(1).text());
                Element tiltTr = generalDataTable.getElementsByTag("tr").get(2);
                membrane.setTiltAngle(tiltTr.getElementsByTag("td").get(1).text());
                Element transferTr = generalDataTable.getElementsByTag("tr").get(3);
                membrane.setDeltaGTransfer(transferTr.getElementsByTag("td").get(1).text());
                Element topologyTr = generalDataTable.getElementsByTag("tr").get(5);
                membrane.setTopology(topologyTr.getElementsByTag("td").get(1).text());
                // extract trans-membrane helices - second table
                Element transMembraneSubunitsTable = document.getElementsByClass("data").get(1);
                List<TransMembraneHelix> helices = transMembraneSubunitsTable.getElementsByTag("tr").stream().skip(1).map(element -> element.getElementsByTag("td").get(0)).map(Element::text).map(TransMembraneHelix::new).collect(Collectors.toList());
                membrane.setTransMembraneHelices(helices);
                protein.getFeatureContainer().addFeature(membrane);
            //                    //TODO remove, used to evaluate alignment manually
            //                    Files.write(Paths.get(System.getProperty("user.home") + "/ori.pdb"), protein.getPdbRepresentation().getBytes());
            //                    Files.write(Paths.get(System.getProperty("user.home") + "/opm.pdb"), opmProtein.getPdbRepresentation().getBytes());
            //                    //TODO remove, used to evaluate segment positions manually
            //                    Files.write(Paths.get(System.getProperty("user.home") + "/tm.pdb"), protein.select()
            //                            .residueNumber(helices.stream()
            //                                    .map(TransMembraneHelix::getSegments)
            //                                    .flatMap(Collection::stream)
            //                                    .collect(Collectors.toList())
            //                                    .toArray(new IntegerRange[0]))
            //                            .asGroupContainer()
            //                            .getPdbRepresentation()
            //                            .getBytes());
            }
        }
    } catch (IOException e) {
        throw new ComputationException("failed to fetch OPM file", e);
    }
}
Also used : AbstractFeatureProvider(de.bioforscher.jstructure.model.feature.AbstractFeatureProvider) ProteinIdentifier(de.bioforscher.jstructure.model.structure.identifier.ProteinIdentifier) ProteinParser(de.bioforscher.jstructure.parser.ProteinParser) Logger(org.slf4j.Logger) ComputationException(de.bioforscher.jstructure.feature.ComputationException) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) SVDSuperimposer(de.bioforscher.jstructure.alignment.SVDSuperimposer) List(java.util.List) ByteArrayInputStream(java.io.ByteArrayInputStream) FeatureProvider(de.bioforscher.jstructure.model.feature.FeatureProvider) Group(de.bioforscher.jstructure.model.structure.Group) Atom(de.bioforscher.jstructure.model.structure.Atom) Document(org.jsoup.nodes.Document) Element(org.jsoup.nodes.Element) Jsoup(org.jsoup.Jsoup) BufferedReader(java.io.BufferedReader) Protein(de.bioforscher.jstructure.model.structure.Protein) Group(de.bioforscher.jstructure.model.structure.Group) InputStreamReader(java.io.InputStreamReader) Element(org.jsoup.nodes.Element) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) URL(java.net.URL) Protein(de.bioforscher.jstructure.model.structure.Protein) Atom(de.bioforscher.jstructure.model.structure.Atom) ByteArrayInputStream(java.io.ByteArrayInputStream) ComputationException(de.bioforscher.jstructure.feature.ComputationException) BufferedReader(java.io.BufferedReader)

Example 2 with Atom

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

the class SecondaryStructureAnnotator method calcSimpleH.

/**
     * Places a pseudo hydrogen atoms between 2 residues, when it is lacking.
     * @param fragmentOfSize2 the fragment where the atom shall be placed
     */
void calcSimpleH(Fragment<AminoAcid> fragmentOfSize2) {
    try {
        double[] c = fragmentOfSize2.getElement(0).getC().getCoordinates();
        double[] o = fragmentOfSize2.getElement(0).getO().getCoordinates();
        double[] n = fragmentOfSize2.getElement(1).getN().getCoordinates();
        double[] xyz = LinearAlgebra.on(c).subtract(o).divide(LinearAlgebra.on(c).distance(o)).add(n).getValue();
        // pdbSerial of minimal int value flags them as pseudo-hydrogen
        fragmentOfSize2.getElement(1).addAtom(new Atom("H", Element.H, xyz));
    } catch (NullPointerException e) {
        //TODO consistent error-handling
        logger.warn("missing backbone atoms for peptide bond between {} and {} - cannot approximate hydrogen atom position", fragmentOfSize2.getElement(0).getIdentifier(), fragmentOfSize2.getElement(1).getIdentifier());
    }
}
Also used : Atom(de.bioforscher.jstructure.model.structure.Atom)

Example 3 with Atom

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

the class EnergyProfileCalculator method processInternally.

@Override
protected void processInternally(Protein protein) {
    final double squaredDistanceCutoff = DEFAULT_INTERACTION_CUTOFF * DEFAULT_INTERACTION_CUTOFF;
    final List<AminoAcid> aminoAcids = protein.aminoAcids().collect(Collectors.toList());
    for (AminoAcid currentGroup : aminoAcids) {
        Optional<Atom> currentGroupBetaCarbon = currentGroup.select().betaCarbonAtoms().asOptionalAtom();
        double[] currentGroupCoordinates = currentGroupBetaCarbon.map(Atom::getCoordinates).orElseGet(() -> currentGroup.calculate().centroid().getValue());
        double solvation = 0;
        double currentGroupSolvationValue = resolve(globularSolvationData, currentGroup);
        for (AminoAcid surroundingGroup : aminoAcids) {
            if (currentGroup.equals(surroundingGroup)) {
                continue;
            }
            Optional<Atom> surroundingGroupBetaCarbon = surroundingGroup.select().betaCarbonAtoms().asOptionalAtom();
            double[] surroundingGroupCoordinates = surroundingGroupBetaCarbon.map(Atom::getCoordinates).orElseGet(() -> surroundingGroup.calculate().centroid().getValue());
            if (LinearAlgebra.on(currentGroupCoordinates).distanceFast(surroundingGroupCoordinates) > squaredDistanceCutoff) {
                continue;
            }
            solvation += currentGroupSolvationValue + resolve(globularSolvationData, surroundingGroup);
        }
        currentGroup.getFeatureContainer().addFeature(new EnergyProfile(this, solvation));
    }
}
Also used : AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Atom(de.bioforscher.jstructure.model.structure.Atom)

Example 4 with Atom

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

the class SelectionTest method shouldFindSimilarNeighbors.

@Test
public void shouldFindSimilarNeighbors() {
    Protein protein = ProteinParser.source("1acj").parse();
    Atom atom = protein.getAtoms().get(100);
    double probeDistance = 4;
    List<Atom> neighboringGroupCountSelectionAPI = protein.select().atomSelection().distance(atom, probeDistance).asFilteredAtoms().collect(Collectors.toList());
    List<Atom> neighboringGroupCountNaive = protein.atoms().filter(a -> a.calculate().distance(atom.getCoordinates()) < probeDistance).collect(Collectors.toList());
    Assert.assertTrue(neighboringGroupCountSelectionAPI.containsAll(neighboringGroupCountNaive));
    Assert.assertTrue(neighboringGroupCountNaive.containsAll(neighboringGroupCountSelectionAPI));
}
Also used : ProteinParser(de.bioforscher.jstructure.parser.ProteinParser) GroupContainer(de.bioforscher.jstructure.model.structure.container.GroupContainer) Arginine(de.bioforscher.jstructure.model.structure.aminoacid.Arginine) Test(org.junit.Test) AtomContainer(de.bioforscher.jstructure.model.structure.container.AtomContainer) Collectors(java.util.stream.Collectors) List(java.util.List) Group(de.bioforscher.jstructure.model.structure.Group) Atom(de.bioforscher.jstructure.model.structure.Atom) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) Optional(java.util.Optional) Phenylalanine(de.bioforscher.jstructure.model.structure.aminoacid.Phenylalanine) Protein(de.bioforscher.jstructure.model.structure.Protein) Assert(org.junit.Assert) Before(org.junit.Before) Protein(de.bioforscher.jstructure.model.structure.Protein) Atom(de.bioforscher.jstructure.model.structure.Atom) Test(org.junit.Test)

Example 5 with Atom

use of de.bioforscher.jstructure.model.structure.Atom 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)

Aggregations

Atom (de.bioforscher.jstructure.model.structure.Atom)7 AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)3 Group (de.bioforscher.jstructure.model.structure.Group)2 Protein (de.bioforscher.jstructure.model.structure.Protein)2 ProteinParser (de.bioforscher.jstructure.parser.ProteinParser)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 SVDSuperimposer (de.bioforscher.jstructure.alignment.SVDSuperimposer)1 ComputationException (de.bioforscher.jstructure.feature.ComputationException)1 AbstractFeatureProvider (de.bioforscher.jstructure.model.feature.AbstractFeatureProvider)1 FeatureProvider (de.bioforscher.jstructure.model.feature.FeatureProvider)1 Chain (de.bioforscher.jstructure.model.structure.Chain)1 Arginine (de.bioforscher.jstructure.model.structure.aminoacid.Arginine)1 Phenylalanine (de.bioforscher.jstructure.model.structure.aminoacid.Phenylalanine)1 AtomContainer (de.bioforscher.jstructure.model.structure.container.AtomContainer)1 GroupContainer (de.bioforscher.jstructure.model.structure.container.GroupContainer)1 ProteinIdentifier (de.bioforscher.jstructure.model.structure.identifier.ProteinIdentifier)1 SelectionException (de.bioforscher.jstructure.model.structure.selection.SelectionException)1 BufferedReader (java.io.BufferedReader)1