FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

New interface finder functionality by josemduarte · Pull Request #867 · biojava/biojava · GitHub

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .java  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Next Next commit
Initial implementation and tests
  • Loading branch information
josemduarte committed Jan 25, 2020
commit 3747377ea45e5b66c97e5cbfcdf30183d871a33d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.biojava.nbio.structure.test.contact;

import org.biojava.nbio.structure.Structure;
import org.biojava.nbio.structure.StructureException;
import org.biojava.nbio.structure.StructureIO;
import org.biojava.nbio.structure.contact.AtomContact;
import org.biojava.nbio.structure.contact.AtomContactSet;
import org.biojava.nbio.structure.contact.InterfaceFinder;
import org.biojava.nbio.structure.contact.Pair;
import org.biojava.nbio.structure.contact.StructureInterface;
import org.biojava.nbio.structure.contact.StructureInterfaceList;
import org.junit.Test;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import static org.junit.Assert.assertEquals;

public class TestInterfaceFinder {

@Test
public void testGetAllInterfaces() throws StructureException, IOException {
Structure s = StructureIO.getStructure("3hbx");
InterfaceFinder finder = new InterfaceFinder(s);

StructureInterfaceList list = finder.getAllInterfaces();

assertEquals(12, list.size());

Set<Pair<String>> unique = new HashSet<>();

for (StructureInterface interf : list) {
System.out.println("Interface " + interf.getMoleculeIds());
AtomContactSet set = interf.getContacts();
System.out.println("Number of contacts: " + set.size());

unique.add(interf.getMoleculeIds());

}
assertEquals(12, unique.size());
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public static List<Group> getUnalignedGroups(Atom[] ca) {
* @see StructureTools#DEFAULT_LIGAND_PROXIMITY_CUTOFF
*/
public static List<Group> getLigandsByProximity(Collection<Group> target, Atom[] query, double cutoff) {
// Geometric hashing of the reduced structure
// Spatial hashing of the reduced structure
Grid grid = new Grid(cutoff);
grid.addAtoms(query);

Expand Down Expand Up @@ -1387,7 +1387,7 @@ public static final Group getGroupByPDBResidueNumber(Structure struc,

/**
* Returns the set of intra-chain contacts for the given chain for given
* atom names, i.e. the contact map. Uses a geometric hashing algorithm that
* atom names, i.e. the contact map. Uses a spatial hashing algorithm that
* speeds up the calculation without need of full distance matrix. The
* parsing mode {@link FileParsingParameters#setAlignSeqRes(boolean)} needs
* to be set to true for this to work.
Expand Down Expand Up @@ -1422,7 +1422,7 @@ public static AtomContactSet getAtomsInContact(Chain chain,

/**
* Returns the set of intra-chain contacts for the given chain for all non-H
* atoms of non-hetatoms, i.e. the contact map. Uses a geometric hashing
* atoms of non-hetatoms, i.e. the contact map. Uses a spatial hashing
* algorithm that speeds up the calculation without need of full distance
* matrix. The parsing mode
* {@link FileParsingParameters#setAlignSeqRes(boolean)} needs to be set to
Expand All @@ -1439,7 +1439,7 @@ public static AtomContactSet getAtomsInContact(Chain chain, double cutoff) {
/**
* Returns the set of intra-chain contacts for the given chain for C-alpha
* atoms (including non-standard aminoacids appearing as HETATM groups),
* i.e. the contact map. Uses a geometric hashing algorithm that speeds up
* i.e. the contact map. Uses a spatial hashing algorithm that speeds up
* the calculation without need of full distance matrix. The parsing mode
* {@link FileParsingParameters#setAlignSeqRes(boolean)} needs to be set to
* true for this to work.
Expand All @@ -1462,7 +1462,7 @@ public static AtomContactSet getAtomsCAInContact(Chain chain, double cutoff) {
/**
* Returns the set of intra-chain contacts for the given chain for C-alpha
* or C3' atoms (including non-standard aminoacids appearing as HETATM
* groups), i.e. the contact map. Uses a geometric hashing algorithm that
* groups), i.e. the contact map. Uses a spatial hashing algorithm that
* speeds up the calculation without need of full distance matrix.
*
* @param chain
Expand All @@ -1483,7 +1483,7 @@ public static AtomContactSet getRepresentativeAtomsInContact(Chain chain,

/**
* Returns the set of inter-chain contacts between the two given chains for
* the given atom names. Uses a geometric hashing algorithm that speeds up
* the given atom names. Uses a spatial hashing algorithm that speeds up
* the calculation without need of full distance matrix. The parsing mode
* {@link FileParsingParameters#setAlignSeqRes(boolean)} needs to be set to
* true for this to work.
Expand Down Expand Up @@ -1518,7 +1518,7 @@ public static AtomContactSet getAtomsInContact(Chain chain1, Chain chain2,

/**
* Returns the set of inter-chain contacts between the two given chains for
* all non-H atoms. Uses a geometric hashing algorithm that speeds up the
* all non-H atoms. Uses a spatial hashing algorithm that speeds up the
* calculation without need of full distance matrix. The parsing mode
* {@link FileParsingParameters#setAlignSeqRes(boolean)} needs to be set to
* true for this to work.
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.biojava.nbio.structure.contact;

import org.biojava.nbio.structure.Chain;
import org.biojava.nbio.structure.Structure;
import org.biojava.nbio.structure.StructureTools;
import org.biojava.nbio.structure.xtal.CrystalTransform;
import org.biojava.nbio.structure.xtal.SpaceGroup;

import java.util.List;

public class InterfaceFinder {

public static final double DEFAULT_CONTACT_CUTOFF = 6;

private static final CrystalTransform IDENTITY_TRANSFORM = new CrystalTransform(SpaceGroup.parseSpaceGroup("P1"));
private static final boolean INCLUDE_HETATOMS = true;

private Structure structure;
private double cutoff;

public InterfaceFinder(Structure structure) {
this.structure = structure;
this.cutoff = DEFAULT_CONTACT_CUTOFF;
}

public void setCutoff(double cutoff) {
this.cutoff = cutoff;
}

public StructureInterfaceList getAllInterfaces() {
StructureInterfaceList list = new StructureInterfaceList();

List<Chain> polyChains = structure.getPolyChains();
for (int i = 0; i<polyChains.size(); i++) {
for (int j = i + 1; j<polyChains.size(); j++) {
StructureInterface interf = calcInterface(polyChains.get(i), polyChains.get(j));
if (interf!=null) {
list.add(interf);
}
}
}
return list;
}

private StructureInterface calcInterface(Chain chain1, Chain chain2) {
AtomContactSet graph = StructureTools.getAtomsInContact(chain1, chain2, cutoff, INCLUDE_HETATOMS);

StructureInterface interf = null;
if (graph.size()>0) {
interf = new StructureInterface(
StructureTools.getAllAtomArray(chain1), StructureTools.getAllAtomArray(chain2),
chain1.getName(), chain2.getName(),
graph,
IDENTITY_TRANSFORM, IDENTITY_TRANSFORM);
}

return interf;
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package org.biojava.nbio.structure.contact;

import org.biojava.nbio.structure.AminoAcidImpl;
import org.biojava.nbio.structure.Atom;
import org.biojava.nbio.structure.AtomImpl;
import org.biojava.nbio.structure.Chain;
import org.biojava.nbio.structure.ChainImpl;
import org.biojava.nbio.structure.EntityInfo;
import org.biojava.nbio.structure.Group;
import org.biojava.nbio.structure.ResidueNumber;
import org.biojava.nbio.structure.Structure;
import org.biojava.nbio.structure.StructureImpl;
import org.biojava.nbio.structure.StructureTools;
import org.junit.Test;
import static org.junit.Assert.*;

import javax.vecmath.Point3d;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class TestInterfaceFinder {

@Test
public void testGetAllInterfaces() {
Structure s = mockStructure();
InterfaceFinder finder = new InterfaceFinder(s);

StructureInterfaceList list = finder.getAllInterfaces();

assertEquals(3, list.size());

Set<Pair<String>> unique = new HashSet<>();

for (StructureInterface interf : list) {
System.out.println("Interface " + interf.getMoleculeIds());
AtomContactSet set = interf.getContacts();
for (AtomContact c : set)
System.out.println(c.getPair() +" - " + c.getDistance());

unique.add(interf.getMoleculeIds());

}
assertEquals(3, unique.size());
}

/**
* Create a mock structure with 2 entities 1 (chains A, B) and 2 (chain C).
* @return a structure
*/
private Structure mockStructure() {
Structure structure = new StructureImpl();
EntityInfo entity1 = new EntityInfo();
entity1.setMolId(1);
EntityInfo entity2 = new EntityInfo();
entity2.setMolId(2);
structure.addEntityInfo(entity1);
structure.addEntityInfo(entity2);

Chain chainA = new ChainImpl();
chainA.setId("A");
chainA.setName("A");
Chain chainB = new ChainImpl();
chainB.setId("B");
chainB.setName("B");
entity1.addChain(chainA);
entity1.addChain(chainB);
Chain chainC = new ChainImpl();
chainC.setId("C");
chainC.setName("C");
entity2.addChain(chainC);

structure.addChain(chainA);
structure.addChain(chainB);
structure.addChain(chainC);

// entity 1: chain A 10 observed residues, chain B 9 observed residues (first unobserved)
List<Group> aGroups = getGroupList(10, "ALA", chainA, new Point3d(0,0,0));
chainA.setAtomGroups(new ArrayList<>(aGroups));
chainA.setSeqResGroups(aGroups);
chainA.setEntityInfo(entity1);

List<Group> bGroups = getGroupList(10, "ALA", chainB, new Point3d(4, 0, 0));
chainB.setAtomGroups(new ArrayList<>(bGroups.subList(1,10)));
chainB.setSeqResGroups(bGroups);
chainB.setEntityInfo(entity1);

List<Group> cGroups = getGroupList(20, "GLY", chainC, new Point3d(0, 4, 0));
chainC.setAtomGroups(new ArrayList<>(cGroups));
chainC.setSeqResGroups(cGroups);
chainC.setEntityInfo(entity2);

return structure;
}

private List<Group> getGroupList(int size, String type, Chain chain, Point3d center) {
List<Group> list = new ArrayList<>();
double offsetx = 0;
double offsety = 0;
double offsetz = 0;
for (int i=0;i<size;i++) {
Group g = new AminoAcidImpl();
g.setPDBName(type);
g.setResidueNumber(new ResidueNumber(chain.getId(), i+1, null));
chain.addGroup(g);
Atom a = new AtomImpl();
a.setName(StructureTools.CA_ATOM_NAME);
a.setX(center.x + offsetx);
a.setY(center.y + offsety);
a.setZ(center.z + offsetz);
g.addAtom(a);
list.add(g);

if (i%3 == 0) offsetx += 1;
if (i%3 == 1) offsety += 1;
if (i%3 == 2) offsetz += 1;
}

return list;
}

}

Back | FazBrowse Home | New Git URL