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
023
024import org.biojava.nbio.structure.Group;
025import org.biojava.nbio.structure.Structure;
026import org.biojava.nbio.structure.io.StructureFiletype;
027import org.biojava.nbio.structure.align.util.AtomCache;
028import org.biojava.nbio.structure.contact.*;
029import org.biojava.nbio.structure.io.FileParsingParameters;
030import org.biojava.nbio.structure.xtal.CrystalBuilder;
031import org.biojava.nbio.structure.xtal.CrystalTransform;
032import org.biojava.nbio.structure.xtal.SpaceGroup;
033import org.biojava.nbio.structure.StructureIO;
034
035import javax.vecmath.AxisAngle4d;
036import javax.vecmath.Vector3d;
037import java.util.List;
038
039
040
041public class DemoCrystalInterfaces {
042
043
044        private static final double BSATOASA_CUTOFF = 0.95;
045        private static final double MIN_ASA_FOR_SURFACE = 5;
046        private static final int CONSIDER_COFACTORS = 40; // minimum number of atoms for a cofactor to be considered, if -1 all ignored
047
048
049        private static final double CUTOFF = 5.5;
050
051        private static final int N_SPHERE_POINTS = 3000;
052
053        private static final double MIN_AREA_TO_KEEP = 35;
054
055        private static final int NTHREADS = Runtime.getRuntime().availableProcessors();
056
057        private static final double CLASH_DISTANCE = 1.5;
058
059
060        /**
061         * @param args
062         */
063        public static void main(String[] args) throws Exception {
064                String pdbCode = "1smt";
065
066                AtomCache cache = new AtomCache();
067                cache.setFiletype(StructureFiletype.CIF);
068
069                FileParsingParameters params = new FileParsingParameters();
070                params.setAlignSeqRes(true);
071                cache.setFileParsingParams(params);
072
073                StructureIO.setAtomCache(cache);
074
075                Structure structure = StructureIO.getStructure(pdbCode);
076
077
078                System.out.println(structure.getPDBCode());
079
080
081                SpaceGroup sg = structure.getCrystallographicInfo().getSpaceGroup();
082
083                if (sg!=null) {
084                        System.out.println(sg.getShortSymbol()+" ("+sg.getId()+")");
085                        System.out.println("Symmetry operators: "+sg.getNumOperators());
086                }
087                System.out.println("Calculating possible interfaces... (using "+NTHREADS+" CPUs for ASA calculation)");
088                long start = System.currentTimeMillis();
089
090                CrystalBuilder cb = new CrystalBuilder(structure);
091
092
093                StructureInterfaceList interfaces = cb.getUniqueInterfaces(CUTOFF);
094                interfaces.calcAsas(N_SPHERE_POINTS, NTHREADS, CONSIDER_COFACTORS);
095                interfaces.removeInterfacesBelowArea(MIN_AREA_TO_KEEP);
096                List<StructureInterfaceCluster> clusters = interfaces.getClusters();
097
098
099                //interfaces.initialiseClusters(pdb, CLUSTERING_CUTOFF, MINATOMS_CLUSTERING, "CA");
100
101                long end = System.currentTimeMillis();
102                long total = (end-start)/1000;
103                System.out.println("Total time for interface calculation: "+total+"s");
104
105                System.out.println("Total number of interfaces found: "+interfaces.size());
106
107                for (int i=0;i<interfaces.size();i++) {
108                        StructureInterface interf = interfaces.get(i+1);
109
110                        String infiniteStr = "";
111                        if (interf.isInfinite()) infiniteStr = " -- INFINITE interface";
112                        System.out.println("\n##Interface "+(i+1)+" "+
113                                        interf.getCrystalIds().getFirst()+"-"+
114                                        interf.getCrystalIds().getSecond()+infiniteStr);
115                        // warning if more than 10 clashes found at interface
116                        List<AtomContact> clashing = interf.getContacts().getContactsWithinDistance(CLASH_DISTANCE);
117                        if (clashing.size()>10)
118                                System.out.println(clashing.size()+" CLASHES!!!");
119
120                        CrystalTransform transf1 = interf.getTransforms().getFirst();
121                        CrystalTransform transf2 = interf.getTransforms().getSecond();
122
123                        System.out.println("Transf1: "+SpaceGroup.getAlgebraicFromMatrix(transf1.getMatTransform())+
124                                        ". Transf2: "+SpaceGroup.getAlgebraicFromMatrix(transf2.getMatTransform()));
125
126
127                        String screwStr = "";
128                        if (transf2.getTransformType().isScrew()) {
129                                Vector3d screwTransl =
130                                                transf2.getTranslScrewComponent();
131                                screwStr = " -- "+transf2.getTransformType().getShortName()+" with translation "+
132                                String.format("(%5.2f,%5.2f,%5.2f)",screwTransl.x,screwTransl.y,screwTransl.z);
133
134                        }
135
136                        if (structure.isCrystallographic()) {
137                                int foldType = sg.getAxisFoldType(transf2.getTransformId());
138                                AxisAngle4d axisAngle = sg.getRotAxisAngle(transf2.getTransformId());
139
140                                System.out.println(" "+foldType+"-fold on axis "+String.format("(%5.2f,%5.2f,%5.2f)",axisAngle.x,axisAngle.y,axisAngle.z)+screwStr);
141                        }
142
143                        System.out.println("Number of contacts: "+interf.getContacts().size());
144                        //System.out.println("Number of contacting atoms (from both molecules): "+interf.getNumAtomsInContact());
145                        Pair<List<Group>> cores = interf.getCoreResidues(BSATOASA_CUTOFF, MIN_ASA_FOR_SURFACE);
146                        System.out.println("Number of core residues at "+String.format("%4.2f", BSATOASA_CUTOFF)+
147                                        " bsa to asa cutoff: "+
148                                        cores.getFirst().size()+" "+
149                                        cores.getSecond().size());
150                        System.out.printf("Interface area: %8.2f\n",interf.getTotalArea());
151
152                        if (interf.isIsologous()) {
153                                System.out.println("Isologous");
154                        } else {
155                                System.out.println("Heterologous");
156                        }
157
158                }
159
160                System.out.println("Interface clusters (one per line): ");
161                for (StructureInterfaceCluster cluster:clusters) {
162                        System.out.print(cluster.getId()+": ");
163                        for (StructureInterface member:cluster.getMembers()) {
164                                System.out.print(member.getId()+" ");
165                        }
166                        System.out.println();
167                }
168
169        }
170
171}