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;
028
029import java.io.IOException;
030
031
032public class DemoContacts {
033
034
035        public static void main(String[] args) throws IOException, StructureException {
036
037                String pdbCode = "1smt";
038
039                demoContacts(pdbCode);
040        }
041
042        private static void demoContacts(String pdbCode) throws IOException, StructureException {
043
044                AtomCache cache = new AtomCache();
045                cache.setUseMmCif(true);
046
047                StructureIO.setAtomCache(cache);
048
049                Structure structure = StructureIO.getStructure(pdbCode);
050
051                Chain chain = structure.getPolyChainByPDB("A");
052
053                String[] atoms = {"CA"};
054                AtomContactSet contacts = StructureTools.getAtomsInContact(chain, atoms, 8.0);
055
056                System.out.println("Contacting residues (on CA atoms)");
057
058                for (AtomContact contact:contacts) {
059                        Atom atom1 = contact.getPair().getFirst();
060                        Atom atom2 = contact.getPair().getSecond();
061
062                        System.out.printf(" %3s-%3s %3s-%3s : %5.2f\n",
063                                        atom1.getGroup().getResidueNumber(),
064                                        atom1.getGroup().getPDBName(),
065                                        atom2.getGroup().getResidueNumber(),
066                                        atom2.getGroup().getPDBName(),
067                                        contact.getDistance());
068                }
069
070                System.out.println("Total number of atom contacts: "+contacts.size());
071
072                GroupContactSet groupContacts = new GroupContactSet(contacts);
073//              for (GroupContact groupContact:groupContacts) {
074//                      Group g1 = groupContact.getPair().getFirst();
075//                      Group g2 = groupContact.getPair().getSecond();
076//
077//                      System.out.printf(" %3s-%3s %3s-%3s : %5.2f\n",
078//                                      g1.getResidueNumber(),
079//                                      g1.getPDBName(),
080//                                      g2.getResidueNumber(),
081//                                      g2.getPDBName(),
082//                                      groupContact.getMinDistance());
083//              }
084                System.out.println("Total number of residue contacts: "+groupContacts.size());
085
086
087                contacts = StructureTools.getAtomsInContact(structure.getChainByIndex(0),structure.getChainByIndex(1),5.5, false);
088
089                System.out.println("Contacting residues between 2 first chains (all non-H non-hetatoms)");
090
091                for (AtomContact contact:contacts) {
092                        Atom atom1 = contact.getPair().getFirst();
093                        Atom atom2 = contact.getPair().getSecond();
094
095                        System.out.printf(" %3s:%1s-%3s-%3s || %3s:%1s-%3s-%3s : %5.2f\n",
096                                        atom1.getGroup().getResidueNumber(),
097                                        atom1.getGroup().getChainId(),
098                                        atom1.getGroup().getPDBName(),
099                                        atom1.getName(),
100                                        atom2.getGroup().getResidueNumber(),
101                                        atom2.getGroup().getChainId(),
102                                        atom2.getGroup().getPDBName(),
103                                        atom2.getName(),
104                                        contact.getDistance());
105                }
106
107                System.out.println("Total number of atom contacts: "+contacts.size());
108
109                groupContacts = new GroupContactSet(contacts);
110                System.out.println("Total number of residue contacts: "+groupContacts.size());
111
112        }
113
114
115}