Java Code Examples for org.biojava.nbio.structure.Structure#getPolyChainByPDB()

The following examples show how to use org.biojava.nbio.structure.Structure#getPolyChainByPDB() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtomCacheTest.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Tests {@link AtomCache#getStructureForDomain(String)} on a multi-chain domain with no ligands but an explicit range (not whole-chain).
 */
@Test
public void testGetStructureForDomain1() throws IOException, StructureException {
	String ranges = "A:328-396,B:518-527";
	Structure whole = cache.getStructure("1h6w");
	AtomPositionMap map = new AtomPositionMap(StructureTools.getAllAtomArray(whole), AtomPositionMap.ANYTHING_MATCHER);
	List<ResidueRangeAndLength> rrs = ResidueRangeAndLength.parseMultiple(ranges, map);
	int expectedLengthA = rrs.get(0).getLength();
	int expectedLengthB = rrs.get(1).getLength();
	Structure structure = cache.getStructureForDomain("d1h6w.2");
	assertEquals(2, structure.getPolyChains().size());
	Chain a = structure.getPolyChainByPDB("A");
	Chain b = structure.getPolyChainByPDB("B");
	assertEquals(expectedLengthA, a.getAtomGroups().size());
	assertEquals(expectedLengthB, b.getAtomGroups().size());
}
 
Example 2
Source File: AtomCacheTest.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Tests {@link AtomCache#getStructureForDomain(String)} on a multi-chain domain with two zinc ligands that occurs after the TER. The ligands are in chains E and F, so they should not be included in the domain.
 */
@Test
public void testGetStructureForDomain2() throws IOException, StructureException {
	String ranges = "A:,B:";
	Structure whole = cache.getStructure("1I3O");
	AtomPositionMap map = new AtomPositionMap(StructureTools.getAllAtomArray(whole), AtomPositionMap.ANYTHING_MATCHER);
	List<ResidueRangeAndLength> rrs = ResidueRangeAndLength.parseMultiple(ranges, map);
	int expectedLengthA = rrs.get(0).getLength();
	int expectedLengthB = rrs.get(1).getLength();
	Structure structure = cache.getStructureForDomain("d1i3o.1");
	assertEquals(2, structure.getPolyChains().size());
	Chain a = structure.getPolyChainByPDB("A");
	Chain b = structure.getPolyChainByPDB("B");
	// since biojava 5.0 we have no ligand or water molecules in the polymer chains, we have to subtract the 3 water molecules
	assertEquals(expectedLengthA - 3, a.getAtomGroups().size());
	// since biojava 5.0 we have no ligand or water molecules in the polymer chains, we have to subtract the 4 water molecules
	assertEquals(expectedLengthB - 4, b.getAtomGroups().size());
	List<Group> ligandsA = StructureTools.filterLigands(b.getAtomGroups());
	assertEquals(0, ligandsA.size());
	List<Group> ligandsB = StructureTools.filterLigands(b.getAtomGroups());
	assertEquals(0, ligandsB.size());
}
 
Example 3
Source File: AtomCacheTest.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Tests {@link AtomCache#getStructureForDomain(String)} on a single-chain domain with two zinc ligands that occurs after the TER.
 */
@Test
public void testGetStructureForDomain3() throws IOException, StructureException {
	String ranges = "E:";
	Structure whole = cache.getStructure("1I3O");
	AtomPositionMap map = new AtomPositionMap(StructureTools.getAllAtomArray(whole), AtomPositionMap.ANYTHING_MATCHER);
	List<ResidueRangeAndLength> rrs = ResidueRangeAndLength.parseMultiple(ranges, map);
	int expectedLengthE = rrs.get(0).getLength();
	Structure structure = cache.getStructureForDomain("d1i3oe_");
	assertEquals(1, structure.getPolyChains().size());
	Chain e = structure.getPolyChainByPDB("E");
	// since biojava 5.0 we have no ligand molecules in the polymer chains, we have to subtract the 2 zinc molecules
	assertEquals(expectedLengthE - 2, e.getAtomGroups().size());

	Chain eligands = structure.getNonPolyChainsByPDB("E").get(0);
	List<Group> ligandsE = StructureTools.filterLigands(eligands.getAtomGroups());
	assertEquals(1, ligandsE.size());
}
 
Example 4
Source File: AtomCacheTest.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test parsing of chain-less ranges (present in SCOP < 1.73)
 * @throws IOException
 * @throws StructureException
 */
@Test
public void testGetStructureForChainlessDomains() throws IOException, StructureException {
	ScopDatabase scop = ScopFactory.getSCOP(ScopFactory.VERSION_1_71); // Uses the range '1-135' without a chain
	Structure structure = cache.getStructureForDomain("d1hcy_1",scop);

	//System.out.println(cache.getStructure("1hcy"));
	//System.out.println(structure);
	assertEquals(1, structure.getPolyChains().size());
	Chain a = structure.getPolyChainByPDB("A");
	int expectedLengthA = 135;
	assertEquals(expectedLengthA, a.getAtomGroups().size());


	assertTrue(structure.hasNonPolyChain("G"));
	assertTrue(structure.hasNonPolyChain("H"));

	Chain copper  = structure.getNonPolyChain("I");
	assertEquals(1,copper.getAtomGroups().size());

}
 
Example 5
Source File: TestDifficultMmCIFFiles.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void test4letterChains() throws IOException, StructureException, URISyntaxException {
	String filename = "/1hh0_4char.cif.gz";
	URL url = getClass().getResource(filename);
	assumeNotNull("Can't find resource "+filename,url);

	File file = new File(url.toURI());
	assumeNotNull(file);
	assumeTrue(file.exists());

	MMCIFFileReader reader = new MMCIFFileReader();
	Structure s = reader.getStructure(file);

	assertNotNull("Failed to load structure from jar",s);

	List<Chain> chains = s.getChains();
	assertEquals("Wrong number of chains",chains.size(), 1);

	Chain chain = chains.get(0);
	assertEquals("Wrong chain ID",chain.getId(),"ABCD");

	Chain chain2 = s.getPolyChainByPDB("ABCD");
	assertNotNull(chain2);
	assertEquals(chain2, chain);
}
 
Example 6
Source File: TestHeaderOnly.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Check that the gapped residues have no atoms, but that ungapped residues
 * have atoms.
 *
 * @param s: Structure to test.
 */
public void check1REPChainC(Structure s) throws StructureException {
	String sequence = "MAETAVINHKKRKNSPRIVQSNDLTEAAYSLSRDQKRMLYLFVDQIRK" +
			"SDGTLQEHDGICEIHVAKYAEIFGLTSAEASKDIRQALKSFAGKEVVFYRPEEDAGDE" +
			"KGYESFPWFIKPAHSPSRGLYSVHINPYLIPFFIGLQNRFTQFRLSETKEITNPYAMR" +
			"LYESLCQYRKPDGSGIVSLKIDWIIERYQLPQSYQRMPDFRRRFLQVCVNEINSRTPM" +
			"RLSYIEKKKGRQTTHIVFSFRDITSMTTG";

	boolean [] shouldMatch = new boolean[sequence.length()];
	for (int i = 0; i < sequence.length(); i++) shouldMatch[i] = true;

	// 1-14 is gap
	for (int i = 0; i < 14; i++) shouldMatch[i] = false;

	// 50-55 is gap
	for (int i = 49; i < 55; i++) shouldMatch[i] = false;

	// 98-109 is gap
	for (int i = 97; i < 109; i++) shouldMatch[i] = false;

	// 247-251 is gap
	for (int i = 246; i < 251; i++) shouldMatch[i] = false;

	Chain c = s.getPolyChainByPDB("C");

	List<Group> seqres = c.getSeqResGroups();

	// Check lengths
	Assert.assertEquals(sequence.length(), seqres.size());

	// Check sequences.
	Assert.assertEquals(sequence, c.getSeqResSequence());

	for (int i = 0; i < sequence.length(); i++) {
		Assert.assertEquals(shouldMatch[i], hasAtoms(seqres.get(i)));
	}
}
 
Example 7
Source File: TestProteinSuperposition.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws StructureException, IOException {
	Structure s = StructureIO.getStructure("1smt");
	Chain origChainA = s.getPolyChainByPDB("A");
	Chain clonedChainA = (Chain) origChainA.clone();

	chain1 = Calc.atomsToPoints(StructureTools.getAtomCAArray(origChainA));
	chain2 = Calc.atomsToPoints(StructureTools.getAtomCAArray(clonedChainA));

}
 
Example 8
Source File: TestHardBioUnits.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This tests that the biounit and operator ids are the right ones when parsing from mmcif
 * @throws IOException
 * @throws StructureException
 */
@Test
public void test4A1Immcif() throws IOException, StructureException {

	String pdbId = "4A1I";
	int biolAssemblyNr = 2;

	AtomCache cache = new AtomCache();
	cache.setUseMmCif(true);
	cache.setUseMmtf(false);
	StructureIO.setAtomCache(cache);

	Structure bioAssembly = StructureIO.getBiologicalAssembly(pdbId,biolAssemblyNr);

	if ( bioAssembly == null){
		System.err.println("Could not generate the biological assembly " + pdbId + " nr " + biolAssemblyNr);
	}


	/*
	 * loop_
			_pdbx_struct_assembly_gen.assembly_id
			_pdbx_struct_assembly_gen.oper_expression
			_pdbx_struct_assembly_gen.asym_id_list
			1 1 A,I,J,K,L,M,N,UA,H,PA,QA,RA,SA,TA,BB
			2 1 G,KA,LA,MA,NA,OA,AB
			2 2 B,O,P,Q,R,VA
			3 1 B,O,P,Q,R,VA
			3 3 G,KA,LA,MA,NA,OA,AB
			4 1 C,S,T,U,V,W,WA,F,FA,GA,HA,IA,JA,ZA
			5 1 D,X,Y,Z,XA,E,AA,BA,CA,DA,EA,YA
	 */

	//System.out.println(bioAssembly.toPDB());

	assertEquals(1, bioAssembly.nrModels());

	assertEquals(2, bioAssembly.getPolyChains().size());

	// this tests checks that the operator ids are exactly those read from mmcif, it doesn't necessarily work in mmtf where there are no ids
	Chain g = bioAssembly.getPolyChainByPDB("G_1");
	Chain b = bioAssembly.getPolyChainByPDB("B_2");

	assertNotNull(g);

	assertNotNull(b);

}
 
Example 9
Source File: CifFileConsumerIntegrationTest.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void comparePDB2cif(String id, String chainId) throws IOException {
    String fileName = binary ? "/" + id + ".bcif" : "/" + id + ".cif";
    System.out.println(fileName);
    InputStream inStream = getClass().getResourceAsStream(fileName);
    assertNotNull("Could not find file " + fileName + ". Config problem?", inStream);

    LocalPDBDirectory reader = binary ? new BcifFileReader() : new CifFileReader();

    FileParsingParameters params = new FileParsingParameters();
    params.setHeaderOnly(headerOnly);
    reader.setFileParsingParameters(params);

    Structure cifStructure = reader.getStructure(inStream);
    assertNotNull(cifStructure);

    // load the PDB file via the PDB parser
    Structure pdbStructure;
    InputStream pinStream = this.getClass().getResourceAsStream("/" + id + ".pdb");
    assertNotNull(inStream);

    PDBFileParser pdbParser = new PDBFileParser();
    pdbParser.setFileParsingParameters(params);

    pdbStructure = pdbParser.parsePDBFile(pinStream);

    assertNotNull(pdbStructure);

    // check NMR data
    assertEquals(id + ": the isNMR flag is not the same!",
            pdbStructure.isNmr(),
            cifStructure.isNmr());

    if (pdbStructure.isNmr()) {
        assertEquals(id + ": the nr of NMR models is not the same!",
                pdbStructure.nrModels(),
                pdbStructure.nrModels());
        checkNMR(pdbStructure);
        checkNMR(cifStructure);
    }

    Chain a_pdb = pdbStructure.getPolyChainByPDB(chainId);
    Chain a_cif = cifStructure.getPolyChainByPDB(chainId);

    String pdb_SEQseq = a_pdb.getSeqResSequence();
    String cif_SEQseq = a_cif.getSeqResSequence();

    assertEquals(id + ": the SEQRES sequences don't match!",
            pdb_SEQseq,
            cif_SEQseq);

    assertEquals(id + ":  The nr of ATOM groups does not match!",
            a_pdb.getAtomGroups(GroupType.AMINOACID).size(),
            a_cif.getAtomGroups(GroupType.AMINOACID).size());

    // actually this check not necessarily works, since there can be waters in PDB that we don;t deal with yet in cif...
    for (int i = 0; i < a_pdb.getAtomGroups(GroupType.AMINOACID).size(); i++) {
        Group gp = a_pdb.getAtomGroups(GroupType.AMINOACID).get(i);
        List<Group> cifGroups = a_cif.getAtomGroups(GroupType.AMINOACID);
        Group gc = cifGroups.get(i);
        checkGroups(gp, gc);
    }

    String pdb_seq = a_pdb.getAtomSequence();
    String cif_seq = a_cif.getAtomSequence();

    assertEquals("the sequences obtained from PDB and mmCif don't match!", pdb_seq, cif_seq);

    List<DBRef> pdb_dbrefs = pdbStructure.getDBRefs();
    List<DBRef> cif_dbrefs = cifStructure.getDBRefs();

    assertEquals("nr of DBrefs found does not match!", pdb_dbrefs.size(), cif_dbrefs.size());

    DBRef p = pdb_dbrefs.get(0);
    DBRef c = cif_dbrefs.get(0);

    String pdb_dbref = p.toPDB();
    String cif_dbref = c.toPDB();
    assertEquals("DBRef is not equal", pdb_dbref, cif_dbref);

    PDBHeader h1 = pdbStructure.getPDBHeader();
    PDBHeader h2 = cifStructure.getPDBHeader();

    if (!h1.toPDB().toUpperCase().equals(h2.toPDB().toUpperCase())) {
        System.err.println(h1.toPDB());
        System.err.println(h2.toPDB());
        assertEquals(h1.toPDB(), h2.toPDB());
    }
    assertEquals("the PDBHeader.toPDB representation is not equivalent",
            h1.toPDB().toUpperCase(),
            h2.toPDB().toUpperCase());
}
 
Example 10
Source File: ChainSorter.java    From symmetry with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Application: Cyclic Symmetry (Cn).
 * <p>
 * Assumes that the input Structure contains the chains in the biological
 * assembly, otherwise the asymmetric unit symmetry will also be detected.
 * 
 * @param structure
 *            Structure containing the Chains
 * @return sorted representative atom array
 * @throws StructureException
 */
public static Atom[] quatSort(Structure structure)
		throws StructureException {

	SubunitClustererParameters clust = new SubunitClustererParameters();
	QuatSymmetryParameters params = new QuatSymmetryParameters();

	QuatSymmetryResults result = QuatSymmetryDetector.calcGlobalSymmetry(
			structure, params, clust);

	if (result.getSymmetry().equals("C1")) { // asymmetric
		/*
		 * List<List<QuatSymmetryResults>> local =
		 * detector.getLocalSymmetries(); if (local.isEmpty()) return
		 * StructureTools.getRepresentativeAtomArray(structure); else result
		 * = local.get(0).get(0);
		 */
		return StructureTools.getRepresentativeAtomArray(structure);
	} else if (!result.getSymmetry().contains("C")) { // non-cyclic
		return StructureTools.getRepresentativeAtomArray(structure);
	}

	List<Integer> chainOrder = new ArrayList<Integer>();
	int axisIndex = result.getRotationGroup().getPrincipalAxisIndex();
	List<Integer> perm = result.getRotationGroup().getRotation(axisIndex)
			.getPermutation();
	int index = 0;

	// Follow the permutations to generate the cyclic order of the chains
	while (chainOrder.size() < perm.size()) {
		chainOrder.add(index);
		index = perm.get(index);
	}

	List<Atom> atomList = new ArrayList<Atom>();
	for (int c : chainOrder) {
		String id = new QuatSymmetrySubunits(result.getSubunitClusters())
				.getChainIds().get(c);
		Chain chain = structure.getPolyChainByPDB(id);
		Atom[] array = StructureTools.getRepresentativeAtomArray(chain);
		for (Atom a : array)
			atomList.add(a);
	}

	return atomList.toArray(new Atom[atomList.size()]);
}
 
Example 11
Source File: ScopTest.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
private void runSCOPTests() throws IOException, StructureException {

		ScopDatabase scop = ScopFactory.getSCOP(ScopFactory.VERSION_1_75);

		List<ScopDomain> domains = scop.getDomainsForPDB("4HHB");

		assertTrue(domains.size() == 4);

		// test case sensitivity;
		List<ScopDomain> domains2 = scop.getDomainsForPDB("4hhb");
		assertTrue(domains2.size() == domains.size());

		//System.out.println(domains);


		String scop1m02 = "d1m02a_	1m02	A:	k.36.1.1	74353	cl=58788,cf=75796,sf=75797,fa=75798,dm=75799,sp=75800,px=74353";

		List<ScopDomain> domains1m02 = scop.getDomainsForPDB("1m02");
		assertTrue(domains1m02.size() == 1);
		ScopDomain d1 = domains1m02.get(0);

		assertNotNull(d1);

		assertEquals("The toString() methods for ScopDomains don't match the scop display",d1.toString(),scop1m02);


		List<ScopDomain> domains1cdg = scop.getDomainsForPDB("1CDG");
		assertTrue(domains1cdg.size() == 4);
		ScopDomain d2 = domains1cdg.get(0);
		assertEquals("Wrong SCOP Id", "d1cdga1", d2.getScopId());
		AtomCache cache = new AtomCache();

		Structure s = cache.getStructureForDomain(d2);
		/*
			The actual SCOP description is A:496-581.
			HET    MAL  A 688      23
			HET    MAL  A 689      23
			HET    MAL  A 690      23
			HET     CA  A 691       1
			HET     CA  A 692       1
			Thus, the two hetero-atoms are out of range.
		 */
		// t
		//checkRange(s,"A:496-581");
		// now with ligands!
		checkRange(s,"A:496-692");






		// check a domain with multiple ranges
		List<ScopDomain> domains1xzp = scop.getDomainsForPDB("1xzp");
		assertTrue(domains1xzp.size() ==4 );




		s = cache.getStructureForDomain(domains1xzp.get(0));

		Chain a = s.getPolyChainByPDB("A");

		// since biojava 5.0, there's no ligands in the polymer chains: thus we substract 3 SO4 molecules present in chain A
		assertEquals(176 -3,a.getAtomGroups().size());



		// check insertion codes

		List<ScopDomain> domains2bq6 = scop.getDomainsForPDB("2bq6");
		assertTrue(domains2bq6.size() == 2);
		ScopDomain target = scop.getDomainByScopID("d2bq6a1");

		assertNotNull(target);

		s = cache.getStructureForDomain(target);

		a = s.getPolyChainByPDB("A");
		assertEquals(a.getAtomGroups().size(),52);
		checkRange(s,"A:1A-49");

	}