org.biojava.nbio.structure.io.FileParsingParameters Java Examples

The following examples show how to use org.biojava.nbio.structure.io.FileParsingParameters. 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: TestMmtfStructureReader.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test for issue https://github.com/biojava/biojava/issues/792
 */
@Test
@Ignore("Issue not fixed yet")
public void checkNonStandardAminoSeqresGroupsPopulated() throws StructureException, IOException {
    // 2X3T, see issue https://github.com/biojava/biojava/issues/792
       // Load a structure in mmtf format
       AtomCache cache = new AtomCache();
       FileParsingParameters params = new FileParsingParameters();
       cache.setFileParsingParams(params);
       cache.setUseMmCif(false);
       cache.setUseMmtf(true);

       StructureIO.setAtomCache(cache);

       ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider());

       Structure structure1 = StructureIO.getStructure("2X3T");
       // chain E is a glycopeptide with unobserved non-standard aminoacids. Because of mmtf limitations (representing seqres sequences as 1-letter strings) the non-standard unobserved residues are read as null
       List<Group> seqresGroups = structure1.getChain("E").getSeqResGroups();
       for (Group g : seqresGroups) {
           assertNotNull("SeqRes group should not be null", g);
       }

   }
 
Example #2
Source File: TestCloning.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * A Structure with alt locs, we make sure they are being cloned too
 *
 * @throws StructureException
 * @throws IOException
 */
@Test
public void test3piuCloning() throws StructureException, IOException {

	final AtomCache cache = new AtomCache();
	final FileParsingParameters params = new FileParsingParameters();
	params.setAlignSeqRes(true);
	cache.setFileParsingParams(params);

	StructureIO.setAtomCache(cache);

	final Structure s = StructureIO.getStructure("3piu");

	final Structure c = s.clone();

	compareCloned(s, c);
}
 
Example #3
Source File: PdbFileFormat30Test.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Structure getStructure(String fileName) throws IOException{

		InputStream inStream = this.getClass().getResourceAsStream(fileName);
		assertNotNull(inStream);

		ChemCompGroupFactory.setChemCompProvider(new ReducedChemCompProvider());
		PDBFileParser pdbpars = new PDBFileParser();
		FileParsingParameters params = new FileParsingParameters();
		params.setAlignSeqRes(false);
		pdbpars.setFileParsingParameters(params);
		Structure structure = null;

		structure = pdbpars.parsePDBFile(inStream) ;

		return structure;
	}
 
Example #4
Source File: TestLongPdbVsMmCifParsing.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() {
	cache = new AtomCache();

	System.out.println("##### Starting long test. THIS CAN TAKE UP TO 1 HOUR TO COMPLETE!");
	System.out.println("##### Using PDB/mmCIF cache dir: "+cache.getPath());
	System.out.println("##### Each dot is a PDB entry being tested. "+DOTS_PER_LINE+" dots per line");

	// disallow the use of the default /tmp dir, to make sure PDB_DIR is set
	if (cache.getPath().equals(System.getProperty("java.io.tmpdir")) ||
		(cache.getPath().equals(System.getProperty("java.io.tmpdir")+File.separator))    ) {

		throw new IllegalArgumentException("PDB_DIR has not been set or it is set to the default temp directory. Please set PDB_DIR to run this test");
	};

	params = new FileParsingParameters();
	cache.setFileParsingParams(params);
	cache.setObsoleteBehavior(ObsoleteBehavior.THROW_EXCEPTION);
}
 
Example #5
Source File: TestAltLocs.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Actually perform the test to see all alt locs are the same size as the main group
 * @throws StructureException
 * @throws IOException
 *
 */
private void doTestAllAltLocsSamAtomsMainGroup(String pdbId) throws IOException, StructureException {
	AtomCache cache = new AtomCache();
	FileParsingParameters params = new FileParsingParameters();
	params.setAlignSeqRes(true);
	params.setCreateAtomBonds(true);
	cache.setFileParsingParams(params);
	StructureIO.setAtomCache(cache);
	Structure structure = StructureIO.getStructure(pdbId);
	// Loop through the atoms
	for ( Chain c: structure.getChains()){
		for (Group g: c.getAtomGroups()){

			for (Group altLocGroup:g.getAltLocs()) {
				assertEquals(g.size(), altLocGroup.size());
			}
		}
	}
}
 
Example #6
Source File: StructureTest.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@BeforeClass
public static void setUp() throws IOException {
	InputStream inStream = StructureTest.class.getResourceAsStream("/5pti_old.pdb");
	assertNotNull(inStream);

	PDBFileParser pdbpars = new PDBFileParser();
	FileParsingParameters params = new FileParsingParameters();
	params.setAlignSeqRes(true);
	params.setCreateAtomBonds(true);
	pdbpars.setFileParsingParameters(params);

	structure = pdbpars.parsePDBFile(inStream) ;

	assertNotNull(structure);

	assertEquals("structure does not contain one chain ", 1 ,structure.size());
}
 
Example #7
Source File: Test4v5a.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test @Ignore
public void test4v5aInternalChainIds() throws StructureException, IOException {
	AtomCache cache = new AtomCache();

	FileParsingParameters params = cache.getFileParsingParams();
	params.setCreateAtomBonds(true);
	StructureIO.setAtomCache(cache);


	// this would throw an exception when making ss bonds from struct_conn because
	// chain id "AD" is both an author chain id and an asym chain id and the chains were
	// getting mixed
	StructureIO.getStructure("4v5a");

	//for (Chain c : s.getChains()) {
	//	System.out.println(c.getChainID()+" "+c.getInternalChainID()+" "+c.getAtomLength());
	//}


}
 
Example #8
Source File: TestQuatSymmetryDetectorExamples.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSymDetectionWithClusteringByEntityId() throws IOException, StructureException {
	AtomCache cache = new AtomCache();
	cache.setUseMmtf(false);
	cache.setUseMmCif(true);
	FileParsingParameters params = new FileParsingParameters();
	params.setAlignSeqRes(true);
	cache.setFileParsingParams(params);
	StructureIO.setAtomCache(cache);
	Structure pdb = StructureIO.getStructure("BIO:1SMT:1");

	SubunitClustererParameters cp = new SubunitClustererParameters();
	cp.setUseEntityIdForSeqIdentityDetermination(true);
	cp.setClustererMethod(SubunitClustererMethod.SEQUENCE);
	QuatSymmetryParameters symmParams = new QuatSymmetryParameters();
	QuatSymmetryResults symmetry = QuatSymmetryDetector.calcGlobalSymmetry(
			pdb, symmParams, cp);

	// C2 symmetry, A2 stoichiometry
	assertEquals("C2", symmetry.getSymmetry());
	assertEquals("A2", symmetry.getStoichiometry().toString());
}
 
Example #9
Source File: MmtfUtils.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Set up the configuration parameters for BioJava.
 * @param extraUrl the string describing the URL (or file path) from which
 * to get missing CCD entries.
 */
public static AtomCache setUpBioJava(String extraUrl) {
	// Set up the atom cache etc
	AtomCache cache = new AtomCache();
	cache.setUseMmCif(true);
	FileParsingParameters params = cache.getFileParsingParams();
	params.setCreateAtomBonds(true);
	params.setAlignSeqRes(true);
	params.setParseBioAssembly(true);
	DownloadChemCompProvider.serverBaseUrl = extraUrl;
	DownloadChemCompProvider.useDefaultUrlLayout = false;
	DownloadChemCompProvider cc = new DownloadChemCompProvider();
	ChemCompGroupFactory.setChemCompProvider(cc);
	cc.checkDoFirstInstall();
	cache.setFileParsingParams(params);
	StructureIO.setAtomCache(cache);
	return cache;
}
 
Example #10
Source File: MmtfUtils.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Set up the configuration parameters for BioJava.
 */
public static AtomCache setUpBioJava() {
	// Set up the atom cache etc
	AtomCache cache = new AtomCache();
	cache.setUseMmCif(true);
	FileParsingParameters params = cache.getFileParsingParams();
	params.setCreateAtomBonds(true);
	params.setAlignSeqRes(true);
	params.setParseBioAssembly(true);
	DownloadChemCompProvider cc = new DownloadChemCompProvider();
	ChemCompGroupFactory.setChemCompProvider(cc);
	cc.checkDoFirstInstall();
	cache.setFileParsingParams(params);
	StructureIO.setAtomCache(cache);
	return cache;
}
 
Example #11
Source File: TestChemCompProvider.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testZipChemCompProvider() throws IOException {
	// Test file input from a stream created from a string.
	InputStream testPDB = new ByteArrayInputStream(DNAexample.getBytes());

	// we just need this to track where to store PDB files
	// this checks the PDB_DIR property (and uses a tmp location if not set)
	UserConfiguration config = new UserConfiguration();
	String cachePath = config.getCacheFilePath();

	// Setup a ChemCompProvider
	Path pdbdir = Paths.get(cachePath);
	Path chemComp = pdbdir.resolve("chemcomp.zip");

	System.out.println("Using PDB_DIR=" + pdbdir.toString() + " as temporary file directory");
	ZipChemCompProvider zp = new ZipChemCompProvider(chemComp.toString(), pdbdir.toString());
	// Keep the .cif.gz files - avoid re-downloading for unit testing.
	zp.setRemoveCif(false);
	ChemCompGroupFactory.setChemCompProvider(zp);

	// Parameters
	FileParsingParameters params = new FileParsingParameters();

	PDBFileReader pdbreader = new PDBFileReader();
	pdbreader.setFileParsingParameters(params);

	Structure s = pdbreader.getStructure(testPDB);
	assertEquals(3, s.getChainByIndex(0).getAtomGroups().size());
	// Not wanted here for testing, but useful for cleaning up downloaded .cif.gz files.
	// ZipChemCompProvider.purgeTempFiles(pdbdir.toString());
}
 
Example #12
Source File: ScanSymmetry.java    From symmetry with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void initializeCache() {
	cache = new AtomCache();
	FileParsingParameters params = cache.getFileParsingParams();
	cache.setUseMmCif(true);
	params.setParseCAOnly(true);
	// MmCifBiolAssemblyProvider mmcifProvider = new
	// MmCifBiolAssemblyProvider();
	// BioUnitDataProviderFactory.setBioUnitDataProvider(mmcifProvider.getClass().getCanonicalName());
	ChemCompGroupFactory.setChemCompProvider(new AllChemCompProvider());
	// ChemCompGroupFactory.setChemCompProvider(new
	// DownloadChemCompProvider());
}
 
Example #13
Source File: DemoLoadSecStruc.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void main(String[] args) throws IOException,
		StructureException {

	String pdbID = "5pti";

	// Only change needed to the DEFAULT Structure loading
	FileParsingParameters params = new FileParsingParameters();
	params.setParseSecStruc(true);

	AtomCache cache = new AtomCache();
	cache.setFileParsingParams(params);

	// Use PDB format, because SS cannot be parsed from mmCIF yet
	cache.setUseMmCif(false);

	// The loaded Structure contains the SS assigned by Author (simple)
	Structure s = cache.getStructure(pdbID);

	// Print the Author's assignment (from PDB file)
	System.out.println("Author's assignment: ");
	printSecStruc(s);

	// If the more detailed DSSP prediction is required call this
	DSSPParser.fetch(pdbID, s, true);

	// Print the assignment residue by residue
	System.out.println("DSSP assignment: ");
	printSecStruc(s);

	// finally use BioJava's built in DSSP-like secondary structure assigner
	SecStrucCalc secStrucCalc = new SecStrucCalc();

	// calculate and assign
	secStrucCalc.calculate(s,true);
	printSecStruc(s);

}
 
Example #14
Source File: TestQuatSymmetryDetectorExamples.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * A performance test that demonstrates how the SubunitClustererParameters.setUseEntityIdForSeqIdentityDetermination()
 * has a dramatic effect in runtime versus doing alignments.
 */
@Ignore("This is a performance test to be run manually")
@Test
public void testSymDetectionPerformanceLargeCapsid() throws IOException, StructureException {
	AtomCache cache = new AtomCache();
	cache.setUseMmtf(false);
	cache.setUseMmCif(true);
	FileParsingParameters params = new FileParsingParameters();
	params.setAlignSeqRes(true);
	params.setParseBioAssembly(true);
	cache.setFileParsingParams(params);
	StructureIO.setAtomCache(cache);

	// making sure we remove all atoms but representative before we expand, otherwise memory requirements are huge
	// 6Q1F is another good example
	Structure au = StructureIO.getStructure("6NHJ");
	StructureTools.reduceToRepresentativeAtoms(au);
	BiologicalAssemblyBuilder builder = new BiologicalAssemblyBuilder();
	List<BiologicalAssemblyTransformation> transforms = au.getPDBHeader().getBioAssemblies().get(1).getTransforms();
	Structure pdb = builder.rebuildQuaternaryStructure(au, transforms, true, false);

	SubunitClustererParameters cp = new SubunitClustererParameters();

	// This is the parameter that makes this fast, set it to false to see the difference.
	// As of git commit ed322e387cd46344a7864a, the difference in runtime is not that huge:
	// 2 minutes with true, 10 minutes with false. I observed a much larger difference before, but can't reproduce anymore - JD 2020-01-23
	cp.setUseEntityIdForSeqIdentityDetermination(true);

	cp.setClustererMethod(SubunitClustererMethod.SEQUENCE);
	QuatSymmetryParameters symmParams = new QuatSymmetryParameters();
	QuatSymmetryResults symmetry = QuatSymmetryDetector.calcGlobalSymmetry(
			pdb, symmParams, cp);

	assertEquals("I", symmetry.getSymmetry());
	assertEquals("A960B960C600D480E300", symmetry.getStoichiometry().toString());
}
 
Example #15
Source File: StructureToolsTest.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testCAmmCIF() throws StructureException {

	//Save the existing ChemCompProvider
	ChemCompProvider provider = ChemCompGroupFactory.getChemCompProvider();
	ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider());

	//mmCIF files left justify their atom names (eg "CA  "), so can have different behavior
	AtomCache pdbCache = new AtomCache();
	pdbCache.setUseMmCif(false);
	FileParsingParameters params = new FileParsingParameters();
	pdbCache.setFileParsingParams(params);

	AtomCache mmcifCache = new AtomCache();
	mmcifCache.setUseMmCif(true);
	FileParsingParameters params2 = new FileParsingParameters();
	mmcifCache.setFileParsingParams(params2);


	Structure pdb=null, mmcif=null;

	String name = "3PIU";
	try {
		pdb = pdbCache.getStructure(name);
		mmcif = mmcifCache.getStructure(name);
	} catch (IOException e) {
		assumeNoException(e);
	}

	Atom[] pdbCA = StructureTools.getRepresentativeAtomArray(pdb);
	Atom[] mmcifCA = StructureTools.getRepresentativeAtomArray(mmcif);

	assertEquals("PDB has wrong length",409,pdbCA.length);
	assertEquals("PDB has wrong length",409,mmcifCA.length);

	ChemCompGroupFactory.setChemCompProvider(provider);
}
 
Example #16
Source File: StructureToolsTest.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testGetAtomsConsistency() throws IOException, StructureException{

	//Save the existing ChemCompProvider
	ChemCompProvider provider = ChemCompGroupFactory.getChemCompProvider();
	ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider());

	AtomCache cache = new AtomCache();
	FileParsingParameters params = new FileParsingParameters();
	cache.setFileParsingParams(params);

	Structure hivA = cache.getStructure("1hiv.A");
	Atom[] caSa = StructureTools.getRepresentativeAtomArray(hivA);
	Atom[] caCa = StructureTools.getRepresentativeAtomArray(hivA.getChainByIndex(0));
	assertEquals("did not find the same number of Atoms from structure and from chain..",
			caSa.length,caCa.length);
	Structure hivB = cache.getStructure("1hiv.B");
	Atom[] caSb = StructureTools.getRepresentativeAtomArray(hivB);
	Atom[] caCb = StructureTools.getRepresentativeAtomArray(hivB.getChainByIndex(0));
	assertEquals("did not find the same number of Atoms from structure and from chain..",
			caSb.length,caCb.length);
	//Both chains have to be the same size (A and B)
	assertEquals(99,caSa.length);
	assertEquals("did not find the same number of Atoms in both chains...",
			caSa.length,caCb.length);
	assertEquals(99,caSa.length);

	ChemCompGroupFactory.setChemCompProvider(provider);
}
 
Example #17
Source File: DemoShowLargeAssembly.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** Load a specific biological assembly for a PDB entry
 *
 * @param pdbId .. the PDB ID
 * @param bioAssemblyId .. the first assembly has the bioAssemblyId 1
 * @return a Structure object or null if something went wrong.
 */
public static Structure  readStructure(String pdbId, int bioAssemblyId) {

	// pre-computed files use lower case PDB IDs
	pdbId = pdbId.toLowerCase();

	// we just need this to track where to store PDB files
	// this checks the PDB_DIR property (and uses a tmp location if not set)
	AtomCache cache = new AtomCache();
	cache.setUseMmCif(true);
	FileParsingParameters p = cache.getFileParsingParams();

	// some bio assemblies are large, we want an all atom representation and avoid
	// switching to a Calpha-only representation for large molecules
	// note, this requires several GB of memory for some of the largest assemblies, such a 1MX4
	p.setAtomCaThreshold(Integer.MAX_VALUE);

	// parse remark 350
	p.setParseBioAssembly(true);

	// download missing files

	Structure structure = null;
	try {
		structure = StructureIO.getBiologicalAssembly(pdbId,bioAssemblyId);
	} catch (Exception e){
		e.printStackTrace();
		return null;
	}
	return structure;
}
 
Example #18
Source File: CifFileConsumerImplTest.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This test represents a common situation for a non-deposited structure.
 * When building with common crystallography software, the user often adds new
 * ligands (or solvent) molecules as new chains.  Only prior to deposition
 * then relabel them so that they belong to the same chain as the polymeric residues.
 *
 * In this case, the ligands represent valuable information and should not be discarded.
 */
@Test
public void testNewLigandChain() throws IOException {
    // Test the file parsing speed when the files are already downloaded.
    InputStream pdbStream = new GZIPInputStream(getClass().getResourceAsStream("/ligandTest.pdb.gz"));
    InputStream cifStream = new GZIPInputStream(getClass().getResourceAsStream("/ligandTest.cif.gz"));

    assertNotNull(cifStream);
    assertNotNull(pdbStream);

    FileParsingParameters params = new FileParsingParameters();
    PDBFileParser pdbpars = new PDBFileParser();
    pdbpars.setFileParsingParameters(params);
    Structure s1 = pdbpars.parsePDBFile(pdbStream) ;

    // The chain B should be present with 1 ligand HEM
    Chain c1 = s1.getNonPolyChainsByPDB("B").get(0);
    assertNotNull(c1);

    int expectedNumLigands = 1;
    assertEquals(expectedNumLigands, c1.getAtomGroups().size());

    Structure s2 = new CifFileReader().getStructure(cifStream);

    // The chain B should be present with 1 ligand HEM
    Chain c2 = s2.getNonPolyChainsByPDB("B").get(0);
    assertNotNull(c2);
    assertEquals(expectedNumLigands, c2.getAtomGroups().size());

    // pdb and mmcif should have same number of chains
    assertEquals(s1.getChains().size(), s2.getChains().size());
}
 
Example #19
Source File: TestEntityHeuristics.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Structure getStructure(String fileName, boolean setAlignSeqRes) throws IOException {
	InputStream inStream = new GZIPInputStream(this.getClass().getResourceAsStream(PATH_TO_TEST_FILES+fileName));

	PDBFileParser pdbpars = new PDBFileParser();
	FileParsingParameters params = new FileParsingParameters();
	params.setAlignSeqRes(setAlignSeqRes);
	pdbpars.setFileParsingParameters(params);

	Structure s = pdbpars.parsePDBFile(inStream) ;

	return s;
}
 
Example #20
Source File: TestEntityResIndexMapping.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void test1SMT() throws IOException, StructureException {


	AtomCache cache = new AtomCache();
	FileParsingParameters params = new FileParsingParameters();
	params.setAlignSeqRes(true);
	cache.setFileParsingParams(params);

	StructureIO.setAtomCache(cache);

	cache.setUseMmCif(false);
	Structure s = StructureIO.getStructure("1SMT");

	Chain chainA = s.getPolyChainByPDB("A");
	int i = chainA.getEntityInfo().getAlignedResIndex(chainA.getAtomGroup(0),chainA);
	assertEquals("First residue in 1smtA "+chainA.getAtomGroup(0).toString()+" should map to 24 in SEQRES",24,i);
	Chain chainB = s.getPolyChainByPDB("B");
	i = chainB.getEntityInfo().getAlignedResIndex(chainB.getAtomGroup(0),chainB);
	assertEquals("First residue in 1smtB "+chainB.getAtomGroup(0).toString()+" should map to 20 in SEQRES",20,i);

	// group with seqres index 19 is observed in chain B but not in chain A, we should still get the index back from getAlignedResIndex
	i = chainA.getEntityInfo().getAlignedResIndex(chainA.getSeqResGroup(19),chainA);
	assertEquals("Seqres residue 20 in 1smtA "+chainA.getSeqResGroup(19).toString()+" should map to 20 in SEQRES",20,i);

	checkAllResidues(s);
}
 
Example #21
Source File: TestEntityResIndexMapping.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Structure getStructure(String fileName, boolean setAlignSeqRes) throws IOException {
	InputStream inStream = new GZIPInputStream(this.getClass().getResourceAsStream(PATH_TO_TEST_FILES+fileName));

	PDBFileParser pdbpars = new PDBFileParser();
	FileParsingParameters params = new FileParsingParameters();
	params.setAlignSeqRes(setAlignSeqRes);
	pdbpars.setFileParsingParameters(params);

	return pdbpars.parsePDBFile(inStream) ;
}
 
Example #22
Source File: TestMmtfRoundTrip.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test that we can round trip a simple structure.
 *
 * @throws IOException an error reading the file
 * @throws StructureException an error parsing the structure
 */
@Test
public void testRoundTrip() throws IOException, StructureException {

	// Load a structure in MMCIF format
	AtomCache cache = new AtomCache();
	FileParsingParameters params = new FileParsingParameters();
	params.setParseBioAssembly(true);
	cache.setFileParsingParams(params);
	cache.setUseMmCif(true);
	
	StructureIO.setAtomCache(cache);

	ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider());

	// test case for biojava issue #770, order of subunits
	Structure structure1 = StructureIO.getStructure("3BW1");
	AdapterToStructureData writerToEncoder = new AdapterToStructureData();
	new MmtfStructureWriter(structure1, writerToEncoder);
	MmtfStructureReader mmtfStructureReader = new MmtfStructureReader();
	new StructureDataToAdapter(writerToEncoder, mmtfStructureReader);
	Structure structure2 = mmtfStructureReader.getStructure();

	assertTrue(checkIfAtomsSame(structure1, structure2));

	checkBioAssemblies1(structure1, structure2);
}
 
Example #23
Source File: TestContactCalc.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@BeforeClass
public static void setupBeforeClass() {
	AtomCache cache = new AtomCache();
	FileParsingParameters params = new FileParsingParameters();
	// it is important to set setAlignSeqRes(true), or otherwise contacts won't be stored correctly
	// since the contacts are stored via using SEQRES as identifiers
	params.setAlignSeqRes(true);
	cache.setFileParsingParams(params);
	StructureIO.setAtomCache(cache);

}
 
Example #24
Source File: Test2JA5.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void test2JA5() throws IOException, StructureException {

	FileParsingParameters fileParsingParameters = new FileParsingParameters();
	fileParsingParameters.setAlignSeqRes(true); // Need to align seqres to match chains.
	fileParsingParameters.setHeaderOnly(false); // Need header only off to have chains to match.

	AtomCache cache = new AtomCache();
	cache.setUseMmCif(false);
	cache.setFileParsingParams(fileParsingParameters);

	StructureIO.setAtomCache(cache);

	Structure s1 = StructureIO.getStructure("2ja5");

	// This is not applicable anymore, we need to parse atoms to have chains to match.
	// assertTrue(StructureTools.getNrAtoms(s1) == 0);

	// SeqRes contains 14 chains, but since we cannot align Chain N to AtomGroups => 14.
	// 2ja5 has been remediated on March 2017, now it has 14 chains in seqres matching the 14 chains in atoms (chain N has been removed)
	assertEquals(14, s1.getPolyChains().size());

	Chain nChain = s1.getPolyChain("N");

	assertNotNull(nChain);

	Chain chain = s1.getPolyChainByPDB("N");
	assertNull(chain);
}
 
Example #25
Source File: TestCloning.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testBondCloning() throws IOException, StructureException {

	final AtomCache cache = new AtomCache();
	cache.setUseMmCif(true);

	final FileParsingParameters params = cache.getFileParsingParams();
	params.setCreateAtomBonds(true);
	cache.setFileParsingParams(params);

	final Structure s = cache.getStructure("2I13");
	List<Bond> bonds = s.getNonPolyChain("G").getAtomGroup(0).getAtom(0).getBonds();
	assertNotNull(bonds);

	Structure s2 = s.clone();
	List<Bond> bonds2 = s2.getNonPolyChain("G").getAtomGroup(0).getAtom(0).getBonds();
	assertNotNull(bonds2);

	assertEquals(bonds.toString(), bonds2.toString());
	// But the objects should be different as the atoms are clones
	assertNotEquals(bonds.toArray(), bonds2.toArray());

	// Also test for polymeric chains
	bonds = s.getPolyChain("E").getAtomGroup(0).getAtom(0).getBonds();
	assertNotNull(bonds);

	s2 = s.clone();
	bonds2 = s2.getPolyChain("E").getAtomGroup(0).getAtom(0).getBonds();
	assertNotNull(bonds2);
}
 
Example #26
Source File: DemoAtomCache.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void demoAtomCache() {
	AtomCache cache = new AtomCache();

	FileParsingParameters params = cache.getFileParsingParams();

	params.setAlignSeqRes(true);
	params.setHeaderOnly(false);
	params.setParseCAOnly(false);
	params.setParseSecStruc(false);

	String[] pdbIDs = new String[]{"4hhb", "1cdg","5pti","1gav", "WRONGID" };

	for (String pdbID : pdbIDs){

		try {
			Structure s = cache.getStructure(pdbID);
			if ( s == null) {
				System.out.println("could not find structure " + pdbID);
				continue;
			}
			// do something with the structure
			System.out.println(s);

		} catch (Exception e){
			// something crazy happened...
			System.err.println("Can't load structure " + pdbID + " reason: " + e.getMessage());
			//e.printStackTrace();
		}
	}

}
 
Example #27
Source File: TestAltLocs.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void test3U7Tmmcif() throws IOException, StructureException{

	// this test intends to check that the mmCIF parser doesn't read twice residues 22 and 25
	// which are annotated as "microheterogeneity" in the SEQRES (entity_poly_seq), see #160

	AtomCache cache = new AtomCache();

	StructureIO.setAtomCache(cache);

	cache.setUseMmCif(true);
	FileParsingParameters params = new FileParsingParameters();
	params.setAlignSeqRes(true);
	cache.setFileParsingParams(params);

	Structure structure = StructureIO.getStructure("3U7T");

	assertNotNull(structure);

	Atom[] ca = StructureTools.getRepresentativeAtomArray(structure);

	//System.out.println(structure.getPdbId() + " has # CA atoms: " + ca.length);

	List<Atom> caList = new ArrayList<Atom>();
	for ( Chain c: structure.getChains()){
		// notice here we test the seqresgroups, because we want to check if microheterogeinity is treated correctly
		for (Group g: c.getSeqResGroups()){

			for (Group altLocGroup:g.getAltLocs()) {
				ensureAllAtomsSameAltCode(altLocGroup, g);
			}

			List<Atom> atoms = g.getAtoms();
			boolean caInMain = false;
			for (Atom a: atoms){

				if ( a.getName().equals(StructureTools.CA_ATOM_NAME)) {
					caList.add(a);
					caInMain = true;
					break;

				}

			}
			if (! caInMain && g.hasAtom(StructureTools.CA_ATOM_NAME)){
				// g.hasAtom checks altLocs
				fail("CA is not in main group, but in altLoc");
			}

		}
	}

	assertEquals(ca.length, caList.size());

}
 
Example #28
Source File: TestAltLocs.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * A test that adding bonds to atoms between groups - doesn't change the size of the groups
 * @throws StructureException
 * @throws IOException
 */
@Test
public void testAddBondsDoesntChangeGroups() throws IOException, StructureException {
	AtomCache cache = new AtomCache();
	FileParsingParameters params = new FileParsingParameters();
	params.setAlignSeqRes(true);
	params.setCreateAtomBonds(true);
	cache.setFileParsingParams(params);
	StructureIO.setAtomCache(cache);
	Structure structure = StructureIO.getStructure("4CUP");
	// Loop through and find
	for (Chain chain : structure.getChains()) {
		List<Group> groups = chain.getAtomGroups();

		for (Group mainGroup : groups) {
			// atoms with no residue number don't have atom information
			if (mainGroup.getResidueNumber() == null) {
				continue;
			}
			if (mainGroup.getAltLocs().isEmpty()) {
				continue;
			}
			int oldSize = mainGroup.size();
			// Now add support for altLocGroup
			List<Atom> atomsList = new ArrayList<>(mainGroup.getAtoms());
			for(Group altLocOne: mainGroup.getAltLocs()){
				for(Atom atomAltLocOne: altLocOne.getAtoms()){
					atomsList.add(atomAltLocOne);
				}
			}
			// Get the chem copm
			ChemComp aminoChemComp = ChemCompGroupFactory.getChemComp(mainGroup
					.getPDBName());
			// Now iterate through this list
			for(Atom atomA : atomsList){

				for (ChemCompBond chemCompBond : aminoChemComp.getBonds()) {

					//
					if(chemCompBond.getAtom_id_1().equals(atomA.getName())){
						// Get the other atom in the group
						for(Atom atomB : atomsList) {
							if(chemCompBond.getAtom_id_2().equals(atomB.getName())){
								int bondOrder = chemCompBond.getNumericalBondOrder();
								new BondImpl(atomA, atomB, bondOrder);
							}
						}
					}
				}
			}
			assertEquals(oldSize, mainGroup.size());
		}
	}
}
 
Example #29
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 #30
Source File: AtomCache.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
public FileParsingParameters getFileParsingParams() {
	return params;
}