Skip to content

Instantly share code, notes, and snippets.

@ucarion
Created July 2, 2013 18:36
Show Gist options
  • Save ucarion/5911877 to your computer and use it in GitHub Desktop.
Save ucarion/5911877 to your computer and use it in GitHub Desktop.
loop through atoms in PDB entry
package com.ulyssecarion.pdb.distances.precalculations;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.biojava.bio.structure.Atom;
import org.biojava.bio.structure.Calc;
import org.biojava.bio.structure.Chain;
import org.biojava.bio.structure.Group;
import org.biojava.bio.structure.Structure;
import org.biojava.bio.structure.StructureException;
import org.biojava.bio.structure.align.util.AtomCache;
import org.biojava.bio.structure.io.FileParsingParameters;
import org.biojava3.structure.StructureIO;
import com.ulyssecarion.pdb.distances.DistanceDataTree;
import com.ulyssecarion.pdb.distances.DistanceResult;
/**
* Creates a data tree for a single PDB entry, but limiting origin groups to
* strictly ligands.
*
* @author Ulysse Carion
*/
public class LigandDistanceDataTreeBuilder {
/**
* If a ligand atom is any further from a potential target atom, it is not
* recorded.
*/
private static final double MAX_DISTANCE = 8.0;
private static AtomCache cache;
static {
cache = new AtomCache();
FileParsingParameters params = cache.getFileParsingParams();
params.setStoreEmptySeqRes(true);
params.setAlignSeqRes(true);
params.setLoadChemCompInfo(true);
}
public static void main(String[] args) {
}
/**
* Adds information about a particular PDB entry to a DistanceDataTree.
*
* @param dataTree
* the DistanceDataTree to add to
* @param pdbID
* the PDB ID of the structure to add information about
*/
public static void buildTreeFor(String pdbID) {
StructureIO.setAtomCache(cache);
int bioAssemblyCount = StructureIO.getNrBiologicalAssemblies(pdbID);
int bioAssemblyId = bioAssemblyCount > 0 ? 1 : 0;
Structure structure = null;
try {
structure = StructureIO.getBiologicalAssembly(pdbID, bioAssemblyId);
} catch (IOException | StructureException e) {
e.printStackTrace();
return;
}
List<Atom> atoms = getAtoms(structure);
try {
for (Atom a : atoms) {
// Whatever
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static List<Atom> getAtoms(Structure s) {
List<Atom> atoms = new ArrayList<>();
List<Chain> model = s.getModel(0);
for (Chain chain : model) {
for (Group group : chain.getAtomGroups()) {
atoms.addAll(group.getAtoms());
}
}
return atoms;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment