package pl.org.ptbi; 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.io.PDBFileReader; public class Main { public static void main(String[] args) { PDBFileReader reader = new PDBFileReader(); reader.setAutoFetch(true); reader.setPath(System.getProperty("java.io.tmpdir")); Structure structure; try { structure = reader.getStructureById("3CFM"); Atom[] atoms = getCarbonAlpha(structure); for (int i = 0; i + 3 < atoms.length; i++) { double torsion = Calc.torsionAngle(atoms[i], atoms[i + 1], atoms[i + 2], atoms[i + 3]); System.out.println(torsion); } } catch (IOException | StructureException e) { e.printStackTrace(); } } private static Atom[] getCarbonAlpha(Structure structure) { List list = new ArrayList<>(); for (Chain chain : structure.getChains()) { for (Group group : chain.getAtomGroups()) { try { Atom atom = group.getAtom("CA"); list.add(atom); } catch (StructureException e) { System.err.println(e.getMessage()); } } } return list.toArray(new Atom[list.size()]); } }