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);
}
}
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());
}
}
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));
}
}
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));
}
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 å as "strong, mostly covalent", 2.5-3.2 å as
* "moderate, mostly electrostatic", 3.2-4.0 å 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);
}
}
Aggregations