use of org.rcsb.mmtf.api.StructureDataInterface in project mm-dev by sbl-sdsc.
the class StructureAligner method getAllVsAllAlignments.
/**
* Calculates all vs. all structural alignments of protein chains using the
* specified alignment algorithm. The input structures must contain single
* protein chains.
*
* @param targets structures containing single protein chains
* @param alignmentAlgorithm name of the algorithm
* @return dataset with alignment metrics
*/
public static Dataset<Row> getAllVsAllAlignments(JavaPairRDD<String, StructureDataInterface> targets, String alignmentAlgorithm) {
SparkSession session = SparkSession.builder().getOrCreate();
JavaSparkContext sc = new JavaSparkContext(session.sparkContext());
// create a list of chainName/ C Alpha coordinates
List<Tuple2<String, Point3d[]>> chains = targets.mapValues(s -> new ColumnarStructureX(s, true).getcAlphaCoordinates()).collect();
// create an RDD of all pair indices (0,1), (0,2), ..., (1,2), (1,3), ...
JavaRDD<Tuple2<Integer, Integer>> pairs = getPairs(sc, chains.size());
// calculate structural alignments for all pairs.
// broadcast (copy) chains to all worker nodes for efficient processing.
// for each pair there can be zero or more solutions, therefore we flatmap the pairs.
JavaRDD<Row> rows = pairs.flatMap(new StructuralAlignmentMapper(sc.broadcast(chains), alignmentAlgorithm));
// convert rows to a dataset
return session.createDataFrame(rows, getSchema());
}
use of org.rcsb.mmtf.api.StructureDataInterface in project mm-dev by sbl-sdsc.
the class MergeMmtf method addEntityInfo.
private static void addEntityInfo(StructureDataInterface[] structures, AdapterToStructureData complex) {
int currentOffset = 0;
int offset = 0;
for (StructureDataInterface structure : structures) {
for (int i = 0; i < structure.getNumEntities(); i++) {
int[] indices = structure.getEntityChainIndexList(i).clone();
// System.out.println("offset: " + offset);
for (int j = 0; j < indices.length; j++) {
indices[j] += offset;
currentOffset = Math.max(currentOffset, indices[j]);
}
complex.setEntityInfo(indices, structure.getEntitySequence(i), structure.getEntityDescription(i), structure.getEntityType(i));
}
offset = currentOffset + 1;
}
}
use of org.rcsb.mmtf.api.StructureDataInterface in project mm-dev by sbl-sdsc.
the class MergeMmtf method initStructure.
private static void initStructure(String structureId, StructureDataInterface[] structures, AdapterToStructureData complex) {
int nBonds = 0;
int nAtoms = 0;
int nGroups = 0;
int nChains = 0;
int nModels = 1;
float resolution = -1;
float rFree = -1;
float rWork = -1;
String title = "";
for (StructureDataInterface s : structures) {
nBonds += s.getNumBonds();
nAtoms += s.getNumAtoms();
nGroups += s.getNumGroups();
nChains += s.getNumChains();
resolution = Math.max(resolution, s.getResolution());
rFree = Math.max(rFree, s.getRfree());
rWork = Math.max(rFree, s.getRwork());
title += s.getTitle();
}
String[] experimentalMethods = { "THEORETICAL MODEL" };
complex.setMmtfProducer("mmtf-spark");
complex.initStructure(nBonds, nAtoms, nGroups, nChains, nModels, structureId);
complex.setHeaderInfo(rFree, rWork, resolution, title, "20180101", "20180101", experimentalMethods);
complex.setModelInfo(0, nChains);
}
use of org.rcsb.mmtf.api.StructureDataInterface in project mm-dev by sbl-sdsc.
the class MergeMmtf method MergeStructures.
public static StructureDataInterface MergeStructures(String structureId, StructureDataInterface... structures) {
for (StructureDataInterface s : structures) {
if (s.getNumModels() != 1) {
throw new IllegalArgumentException("ERROR: Cannot merge structures with more than one model");
}
}
AdapterToStructureData complex = new AdapterToStructureData();
initStructure(structureId, structures, complex);
addEntityInfo(structures, complex);
for (StructureDataInterface structure : structures) {
addStructure(structure, complex);
}
complex.finalizeStructure();
return complex;
}
use of org.rcsb.mmtf.api.StructureDataInterface in project mm-dev by sbl-sdsc.
the class D3RLigandProteinMerger method main.
public static void main(String[] args) throws IOException {
long start = System.nanoTime();
// instantiate Spark
SparkConf conf = new SparkConf().setMaster("local[*]").setAppName("D3RLigandProteinMerger");
JavaSparkContext sc = new JavaSparkContext(conf);
// String path = "/Users/peter/Downloads/Pose_prediction/417-1-hciq4/";
String path = "/Users/peter/Downloads/Pose_prediction/";
JavaPairRDD<String, StructureDataInterface> ligands = Molmporter.importMolFiles(path, sc);
ligands = ligands.mapToPair(t -> new Tuple2<String, StructureDataInterface>(removeExtension(t._1), t._2));
JavaPairRDD<String, StructureDataInterface> proteins = MmtfImporter.importPdbFiles(path, sc);
proteins = proteins.mapToPair(t -> new Tuple2<String, StructureDataInterface>(removeExtension(t._1), t._2));
JavaPairRDD<String, Tuple2<StructureDataInterface, StructureDataInterface>> pairs = proteins.join(ligands);
JavaPairRDD<String, StructureDataInterface> complexes = pairs.mapToPair(t -> new Tuple2<String, StructureDataInterface>(t._1, MergeMmtf.MergeStructures(t._1, t._2._1, t._2._2)));
complexes.foreach(t -> TraverseStructureHierarchy.printChainInfo(t._2));
// System.out.println("Complexes: " + complexes.count());
// complexes.keys().foreach(k -> System.out.println(k));
// TraverseStructureHierarchy.printChainInfo(complexes.first()._2);
sc.close();
long end = System.nanoTime();
System.out.println("Time: " + (end - start) / 1E9 + " sec.");
}
Aggregations