001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021package demo; 022 023import org.biojava.nbio.structure.*; 024import org.biojava.nbio.structure.align.util.AtomCache; 025import org.biojava.nbio.structure.contact.AtomContact; 026import org.biojava.nbio.structure.contact.AtomContactSet; 027import org.biojava.nbio.structure.contact.GroupContactSet; 028import org.biojava.nbio.structure.io.StructureFiletype; 029 030import java.io.IOException; 031 032 033public class DemoContacts { 034 035 036 public static void main(String[] args) throws IOException, StructureException { 037 038 String pdbCode = "1smt"; 039 040 demoContacts(pdbCode); 041 } 042 043 private static void demoContacts(String pdbCode) throws IOException, StructureException { 044 045 AtomCache cache = new AtomCache(); 046 cache.setFiletype(StructureFiletype.CIF); 047 048 StructureIO.setAtomCache(cache); 049 050 Structure structure = StructureIO.getStructure(pdbCode); 051 052 Chain chain = structure.getPolyChainByPDB("A"); 053 054 String[] atoms = {"CA"}; 055 AtomContactSet contacts = StructureTools.getAtomsInContact(chain, atoms, 8.0); 056 057 System.out.println("Contacting residues (on CA atoms)"); 058 059 for (AtomContact contact:contacts) { 060 Atom atom1 = contact.getPair().getFirst(); 061 Atom atom2 = contact.getPair().getSecond(); 062 063 System.out.printf(" %3s-%3s %3s-%3s : %5.2f\n", 064 atom1.getGroup().getResidueNumber(), 065 atom1.getGroup().getPDBName(), 066 atom2.getGroup().getResidueNumber(), 067 atom2.getGroup().getPDBName(), 068 contact.getDistance()); 069 } 070 071 System.out.println("Total number of atom contacts: "+contacts.size()); 072 073 GroupContactSet groupContacts = new GroupContactSet(contacts); 074// for (GroupContact groupContact:groupContacts) { 075// Group g1 = groupContact.getPair().getFirst(); 076// Group g2 = groupContact.getPair().getSecond(); 077// 078// System.out.printf(" %3s-%3s %3s-%3s : %5.2f\n", 079// g1.getResidueNumber(), 080// g1.getPDBName(), 081// g2.getResidueNumber(), 082// g2.getPDBName(), 083// groupContact.getMinDistance()); 084// } 085 System.out.println("Total number of residue contacts: "+groupContacts.size()); 086 087 088 contacts = StructureTools.getAtomsInContact(structure.getChainByIndex(0),structure.getChainByIndex(1),5.5, false); 089 090 System.out.println("Contacting residues between 2 first chains (all non-H non-hetatoms)"); 091 092 for (AtomContact contact:contacts) { 093 Atom atom1 = contact.getPair().getFirst(); 094 Atom atom2 = contact.getPair().getSecond(); 095 096 System.out.printf(" %3s:%1s-%3s-%3s || %3s:%1s-%3s-%3s : %5.2f\n", 097 atom1.getGroup().getResidueNumber(), 098 atom1.getGroup().getChainId(), 099 atom1.getGroup().getPDBName(), 100 atom1.getName(), 101 atom2.getGroup().getResidueNumber(), 102 atom2.getGroup().getChainId(), 103 atom2.getGroup().getPDBName(), 104 atom2.getName(), 105 contact.getDistance()); 106 } 107 108 System.out.println("Total number of atom contacts: "+contacts.size()); 109 110 groupContacts = new GroupContactSet(contacts); 111 System.out.println("Total number of residue contacts: "+groupContacts.size()); 112 113 } 114 115 116}