Search in sources :

Example 11 with AminoAcid

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

the class A04A_CreatePyMolRendering method handleChain.

private static void handleChain(ExplorerChain explorerChain) {
    logger.info("handling chain {}", explorerChain.getStfId());
    try {
        Chain nativeChain = explorerChain.getChain();
        Path nativeChainPath = Files.createTempFile("nativechain-", ".pdb");
        Files.write(nativeChainPath, nativeChain.getPdbRepresentation().getBytes());
        ReconstructionContactMap nativeContactMap = ReconstructionContactMap.createReconstructionContactMap(nativeChain, ContactDefinitionFactory.createAlphaCarbonContactDefinition(8.0));
        List<AminoAcid> aminoAcids = nativeChain.getAminoAcids();
        List<Pair<AminoAcid, AminoAcid>> contacts = nativeContactMap.getLongRangeContacts();
        int numberNativeLongRangeContacts = contacts.size();
        List<ReconstructionContactMap> reconstructionContactMaps = new ArrayList<>();
        IntStream.of(5, 30, 100).forEach(coverage -> {
            int numberOfContactsToSelect = (int) Math.round(0.01 * coverage * numberNativeLongRangeContacts);
            for (int run = 0; run < REDUNDANCY; run++) {
                Collections.shuffle(contacts);
                List<Pair<AminoAcid, AminoAcid>> selectedContacts = contacts.subList(0, numberOfContactsToSelect);
                ReconstructionContactMap contactMap = new ReconstructionContactMap(aminoAcids, selectedContacts, nativeContactMap.getContactDefinition());
                contactMap.setName("p" + coverage + "-" + (run + 1));
                reconstructionContactMaps.add(contactMap);
            }
        });
        Map<String, List<Future<ReconstructionResult>>> reconstructionFutures = new HashMap<>();
        for (ReconstructionContactMap contactMap : reconstructionContactMaps) {
            String name = contactMap.getName().split("-")[0];
            logger.info("handling contact map with coverage {}", name);
            if (!reconstructionFutures.containsKey(name)) {
                reconstructionFutures.put(name, new ArrayList<>());
            }
            List<Future<ReconstructionResult>> bin = reconstructionFutures.get(name);
            bin.add(executorService.submit(new ConfoldServiceWorker("/home/sb/programs/confold_v1.0/confold.pl", contactMap.getSequence(), contactMap.getSecondaryStructureElements(), contactMap.getCaspRRRepresentation(), nativeContactMap.getConfoldRRType())));
        }
        for (Map.Entry<String, List<Future<ReconstructionResult>>> reconstructionFuture : reconstructionFutures.entrySet()) {
            try {
                String name = reconstructionFuture.getKey();
                List<Chain> reconstructions = reconstructionFuture.getValue().stream().map(future -> {
                    try {
                        return future.get();
                    } catch (Exception e) {
                        throw new ComputationException(e);
                    }
                }).map(ReconstructionResult::getChains).flatMap(Collection::stream).collect(Collectors.toList());
                for (Chain reconstructedChain : reconstructions) {
                    Files.write(OUTPUT_PATH.resolve(name + ".pdb"), reconstructedChain.getPdbRepresentation().getBytes());
                }
            } catch (IOException e) {
                throw new ComputationException(e);
            }
        }
    } catch (IOException e) {
        throw new ComputationException(e);
    }
}
Also used : IntStream(java.util.stream.IntStream) java.util(java.util) Logger(org.slf4j.Logger) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) Files(java.nio.file.Files) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) TestUtils(de.bioforscher.testutil.TestUtils) Collectors(java.util.stream.Collectors) Pair(de.bioforscher.jstructure.mathematics.Pair) Executors(java.util.concurrent.Executors) ConfoldServiceWorker(de.bioforscher.jstructure.si.ConfoldServiceWorker) Future(java.util.concurrent.Future) Paths(java.nio.file.Paths) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) ExplorerChain(de.bioforscher.jstructure.si.explorer.ExplorerChain) ReconstructionResult(de.bioforscher.jstructure.si.model.ReconstructionResult) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) ContactDefinitionFactory(de.bioforscher.jstructure.graph.contact.definition.ContactDefinitionFactory) Chain(de.bioforscher.jstructure.model.structure.Chain) ExplorerChain(de.bioforscher.jstructure.si.explorer.ExplorerChain) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) ReconstructionResult(de.bioforscher.jstructure.si.model.ReconstructionResult) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) Pair(de.bioforscher.jstructure.mathematics.Pair) Path(java.nio.file.Path) ConfoldServiceWorker(de.bioforscher.jstructure.si.ConfoldServiceWorker) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) IOException(java.io.IOException) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) IOException(java.io.IOException) Future(java.util.concurrent.Future) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap)

Example 12 with AminoAcid

use of de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid 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 13 with AminoAcid

use of de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid 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 14 with AminoAcid

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

the class EnergyProfileCalculator method processInternally.

@Override
protected void processInternally(Structure 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 15 with AminoAcid

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

the class A01_CreatePyMolRenderJobsForEarlyFoldingResidues method composePyMolCommand.

private static String composePyMolCommand(String line) {
    String[] split = line.split(";");
    String entryId = split[0];
    String pdbId = split[1];
    List<Integer> experimentIds = Pattern.compile(",").splitAsStream(split[2].replaceAll("\\[", "").replaceAll("]", "")).map(Integer::valueOf).collect(Collectors.toList());
    Structure structure = StructureParser.fromPdbId(pdbId).parse();
    Chain chain = structure.chains().findFirst().get();
    Start2FoldXmlParser.parseSpecificExperiment(chain, Start2FoldConstants.XML_DIRECTORY.resolve(entryId + ".xml"), experimentIds);
    List<Integer> earlyFoldingResidues = chain.aminoAcids().filter(aminoAcid -> aminoAcid.getFeature(Start2FoldResidueAnnotation.class).isEarly()).map(AminoAcid::getResidueIdentifier).map(ResidueIdentifier::getResidueNumber).collect(Collectors.toList());
    return "delete all" + System.lineSeparator() + "fetch " + pdbId + ", async=0" + System.lineSeparator() + // hide non-relevant stuff
    "hide everything" + System.lineSeparator() + "show cartoon, chain A" + System.lineSeparator() + // decolor everything
    "color grey80" + System.lineSeparator() + "zoom (chain A)" + System.lineSeparator() + earlyFoldingResidues.stream().map(res -> "color efr, resi " + res).collect(Collectors.joining(System.lineSeparator())) + System.lineSeparator() + "ray" + System.lineSeparator() + "png " + Start2FoldConstants.PYMOL_DIRECTORY.resolve(entryId + "-efr.png") + System.lineSeparator();
}
Also used : Start2FoldResidueAnnotation(de.bioforscher.jstructure.efr.model.Start2FoldResidueAnnotation) Files(java.nio.file.Files) ResidueIdentifier(de.bioforscher.jstructure.model.identifier.ResidueIdentifier) Structure(de.bioforscher.jstructure.model.structure.Structure) IOException(java.io.IOException) StructureParser(de.bioforscher.jstructure.model.structure.StructureParser) Collectors(java.util.stream.Collectors) Start2FoldXmlParser(de.bioforscher.jstructure.efr.parser.Start2FoldXmlParser) Start2FoldConstants(de.bioforscher.jstructure.efr.Start2FoldConstants) List(java.util.List) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) StandardFormat(de.bioforscher.jstructure.StandardFormat) Pattern(java.util.regex.Pattern) Chain(de.bioforscher.jstructure.model.structure.Chain) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Start2FoldResidueAnnotation(de.bioforscher.jstructure.efr.model.Start2FoldResidueAnnotation) Structure(de.bioforscher.jstructure.model.structure.Structure)

Aggregations

AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)66 Chain (de.bioforscher.jstructure.model.structure.Chain)40 Collectors (java.util.stream.Collectors)40 IOException (java.io.IOException)36 Files (java.nio.file.Files)35 List (java.util.List)31 StandardFormat (de.bioforscher.jstructure.StandardFormat)26 StructureParser (de.bioforscher.jstructure.model.structure.StructureParser)26 Path (java.nio.file.Path)25 Structure (de.bioforscher.jstructure.model.structure.Structure)23 Pattern (java.util.regex.Pattern)17 Logger (org.slf4j.Logger)16 LoggerFactory (org.slf4j.LoggerFactory)16 Start2FoldResidueAnnotation (de.bioforscher.jstructure.efr.model.Start2FoldResidueAnnotation)15 UncheckedIOException (java.io.UncheckedIOException)14 ArrayList (java.util.ArrayList)14 Stream (java.util.stream.Stream)14 Start2FoldResidueAnnotation (de.bioforscher.start2fold.model.Start2FoldResidueAnnotation)13 Optional (java.util.Optional)13 Pair (de.bioforscher.jstructure.mathematics.Pair)11