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