org.biojava.nbio.structure.Structure Java Examples

The following examples show how to use org.biojava.nbio.structure.Structure. 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: Subunit.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * A Subunit is solely defined by the coordinates of the representative
 * Atoms of its residues. It can be identified with a StructureIdentifier
 * and/or a name and stores a reference to the Structure from which the
 * Atoms were obtained.
 *
 * @param reprAtoms
 *            representative Atoms. It cannot be null or empty
 * @param name
 *            String field that identifies the Subunit. It can be null
 * @param identifier
 *            StructureIdentifier. It can be null
 * @param structure
 *            parent Structure object. It can be null
 */
public Subunit(Atom[] reprAtoms, String name,
		StructureIdentifier identifier, Structure structure) {

	if (reprAtoms == null)
		throw new IllegalArgumentException(
				"Representative Atom Array of the Subunit is null");
	if (reprAtoms.length==0)
		throw new IllegalArgumentException(
				"Representative Atom Array of the Subunit has 0 length");

	this.reprAtoms = reprAtoms;
	this.name = name;
	this.identifier = identifier;
	this.structure = structure;
}
 
Example #2
Source File: TestMmtfStructureReader.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Compare structures loaded from MMCIF and MMTF files.
 */
@Test
public void compareMmcif() throws IOException, StructureException {
	
	// Get the MMTF and MMCIF files from the resources folder
	ClassLoader classLoader = getClass().getClassLoader();
	String resource = "org/biojava/nbio/structure/io/mmtf/4CUP";
	
	// Load the structures into memory
	Structure mmtf = MmtfActions.readFromFile((
			Paths.get(classLoader.getResource(resource + ".mmtf").getPath())));
	Structure mmcif = StructureIO.getStructure(classLoader.getResource(resource + ".cif").getPath());
	
	// Compare the dates of the structure
	assertEquals(mmcif.getPDBHeader().getDepDate(), 
			mmtf.getPDBHeader().getDepDate());
	
	// Compare the experimental method
	assertEquals(mmcif.getPDBHeader().getExperimentalTechniques(), 
			mmtf.getPDBHeader().getExperimentalTechniques());
	
	// Compare the SEQRES, see issue https://github.com/biojava/biojava/issues/671
	assertEquals(mmcif.getChainByIndex(0).getSeqResSequence(), 
			mmtf.getChainByIndex(0).getSeqResSequence());
	
}
 
Example #3
Source File: TestCrystallographicMetadata.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void test4hhb() throws Exception {

	AtomCache cache = new AtomCache();
	// at the moment implemented only in mmcif
	cache.setUseMmCif(true);
	StructureIO.setAtomCache(cache);

	Structure s = StructureIO.getStructure("4hhb");

	// 4hhb is one of the few entries that aren't in the standard coordinate frame convention
	assertTrue(s.getCrystallographicInfo().isNonStandardCoordFrameConvention());

	// 4hhn has a standard SG
	assertFalse(s.getCrystallographicInfo().isNonStandardSg());
	assertNotNull(s.getCrystallographicInfo().getSpaceGroup());
}
 
Example #4
Source File: TestCrystalBuilder.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void test2H2Z() throws IOException, StructureException {

	// a crystallographic structure C 1 2 1.
	// Should have a minimum number of contacts of 3, from the C number given in:
	// Wukowitz & Yeates, Nature Structural Biology, 1995
	// the molecule happens to be placed quite far from the origin, so this tests if we really capture all contacts

	AtomCache cache = new AtomCache();

	StructureIO.setAtomCache(cache);

	cache.setUseMmCif(true);
	Structure s1 = StructureIO.getStructure("2H2Z");
	CrystalBuilder cb = new CrystalBuilder(s1);
	StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5);
	assertEquals(3,interfaces.size());

}
 
Example #5
Source File: TestCrystalBuilder.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void test1AUY() throws IOException, StructureException {
	// a virus with NCS operators
	AtomCache cache = new AtomCache();
	StructureIO.setAtomCache(cache);
	cache.setUseMmCif(true);
	Structure s1 = StructureIO.getStructure("1AUY");

	Map<String,Matrix4d> chainNcsOps = new HashMap<>();
	Map<String,String> chainOrigNames = new HashMap<>();

	CrystalBuilder.expandNcsOps(s1,chainOrigNames,chainNcsOps);

	CrystalBuilder cb = new CrystalBuilder(s1,chainOrigNames,chainNcsOps);
	StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5);
	assertEquals(186,interfaces.size());
	assertEquals(24,interfaces.getClustersNcs().size());

	// kill the cell info to simulate incorrect and/or missing
	s1.getCrystallographicInfo().setCrystalCell(null);
	cb = new CrystalBuilder(s1,chainOrigNames,chainNcsOps);
	interfaces = cb.getUniqueInterfaces(5.5);
	//only interfaces within AU
	assertEquals(132,interfaces.size());
	assertEquals(12,interfaces.getClustersNcs().size());
}
 
Example #6
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 #7
Source File: TestNonDepositedFiles.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void test4B19() throws IOException, StructureException {
	InputStream inStream = new GZIPInputStream(this.getClass().getResourceAsStream("/org/biojava/nbio/structure/io/4b19_raw.pdb.gz"));
	assertNotNull(inStream);

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

	Structure s = pdbpars.parsePDBFile(inStream) ;

	// multi-model NMR entry, thus:
	assertTrue(s.isNmr());
	assertFalse(s.isCrystallographic());
	assertTrue(s.nrModels()>1);
	assertNull(s.getPDBHeader().getExperimentalTechniques());

}
 
Example #8
Source File: PDBFileParserTest.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testMultiLineJRNL() throws IOException {
	//            System.out.println("Testing JRNL record parsing from 3pfk");
	String jrnlString =
			"JRNL        AUTH   P.R.EVANS,G.W.FARRANTS,P.J.HUDSON                            " + newline +
			"JRNL        TITL   PHOSPHOFRUCTOKINASE: STRUCTURE AND CONTROL.                  " + newline +
			"JRNL        REF    PHILOS.TRANS.R.SOC.LONDON,    V. 293    53 1981              " + newline +
			"JRNL        REF  2 SER.B                                                        " + newline +
			"JRNL        REFN                   ISSN 0080-4622                               " + newline +
			"JRNL        PMID   6115424                                                      ";


	BufferedReader br = new BufferedReader(new StringReader(jrnlString));
	Structure s = null;

	s = parser.parsePDBFile(br);

	// String jrnl = s.getJournalArticle().toString();
	//            System.out.println(jrnl);
	JournalArticle journalArticle = s.getJournalArticle();
	assertEquals("293", journalArticle.getVolume());
	assertEquals("53", journalArticle.getStartPage());
	assertEquals(1981, journalArticle.getPublicationDate());
	assertEquals("PHILOS.TRANS.R.SOC.LONDON, SER.B", journalArticle.getJournalName());
}
 
Example #9
Source File: MultiThreadedDBSearch.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
public MultiThreadedDBSearch(String name, Structure structure,
		String outFile,
		StructureAlignment algorithm,
		int nrCPUs, boolean domainSplit){

	interrupted = new AtomicBoolean(false);
	this.name1= name;
	this.structure1 = structure;
	this.outFile = outFile;
	this.algorithm = algorithm;
	this.nrCPUs = nrCPUs;
	this.domainSplit = domainSplit;
	cache  = new AtomCache();

	String serverLocation = FarmJobParameters.DEFAULT_SERVER_URL;
	if ( representatives == null){
		SortedSet<String> repre = JFatCatClient.getRepresentatives(serverLocation,40);
		logger.info("got {} representatives for comparison", repre.size());
		representatives = repre;
	}
}
 
Example #10
Source File: TestParseMmcifHeader.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test parsing dates from MMCIF file version 4.
 */
@Test
public void testDatesV4() throws IOException, StructureException, ParseException {

	ClassLoader classLoader = this.getClass().getClassLoader();
	String file4 = classLoader.getResource("org/biojava/nbio/structure/io/mmcif/1stp_v4.cif").getPath();
	Structure s = StructureIO.getStructure(file4);

	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.US);

	Date modDate = dateFormat.parse("2011-07-13");
	assertEquals(modDate, s.getPDBHeader().getModDate());

	Date releaseDate = dateFormat.parse("1992-10-15");
	assertEquals(releaseDate, s.getPDBHeader().getRelDate());

	Date depositionDate = dateFormat.parse("1992-03-12");
	assertEquals(depositionDate, s.getPDBHeader().getDepDate());

}
 
Example #11
Source File: SymmetryTools.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the representative Atom Array of the first model, if the
 * structure is NMR, or the Array for each model, if it is a biological
 * assembly with multiple models.
 *
 * @param structure
 * @return representative Atom[]
 */
public static Atom[] getRepresentativeAtoms(Structure structure) {

	if (structure.isNmr())
		return StructureTools.getRepresentativeAtomArray(structure);

	else {

		// Get Atoms of all models
		List<Atom> atomList = new ArrayList<Atom>();
		for (int m = 0; m < structure.nrModels(); m++) {
			for (Chain c : structure.getModel(m))
				atomList.addAll(Arrays.asList(StructureTools
						.getRepresentativeAtomArray(c)));
		}
		return atomList.toArray(new Atom[0]);
	}

}
 
Example #12
Source File: TestHeaderOnly.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testSpeed() {
	// Force using a file reader.
	MMCIFFileReader fr = new MMCIFFileReader();
	FileParsingParameters par = new FileParsingParameters();
	//par.setAlignSeqRes(true);
	// par.setHeaderOnly(true);
	par.setHeaderOnly(false);
	fr.setFileParsingParameters(par);
	fr.setFetchBehavior(FetchBehavior.FETCH_FILES);

	Structure s = null;
	long start = System.nanoTime();
	try {
		// Medium sized structure parsed in 0.549s (no header) vs .676s (header) ~ 20% faster
		s = fr.getStructureById("4WZ6");
		// A larger structure could be parsed ~ 4.991s (no header) vs 5.867s (header) ~ 16% faster
		// s = fr.getStructureById("4V60");
	} catch (IOException e) {
		e.printStackTrace();
		System.exit(1);
	}
	long stop = System.nanoTime();
	double diff = (stop - start) / 1000000000.0;
	logger.info(String.format("[%s] Elapsed time: %.3f s", s.getIdentifier(), diff));
}
 
Example #13
Source File: PDBFileParserTest.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testInvalidFormatREFsectionJRNL() throws IOException{
	//            System.out.println("Testing JRNL record parsing from 3pfk");
	String jrnlString =
			"JRNL        AUTH   P.R.EVANS,G.W.FARRANTS,P.J.HUDSON                            " + newline +
			//            "JRNL        TITL   PHOSPHOFRUCTOKINASE: STRUCTURE AND CONTROL.                  " + newline +
			"JRNL        REF    INTERESTING TIMES                                            " + newline +
			"JRNL        REFN                   ISSN 0080-4622                               " + newline +
			"JRNL        PMID   6115424                                                      ";


	BufferedReader br = new BufferedReader(new StringReader(jrnlString));
	Structure s = null;
	s = parser.parsePDBFile(br);
	// String jrnl = s.getJournalArticle().toString();
	//            System.out.println(jrnl);
	JournalArticle journalArticle = s.getJournalArticle();
	assertEquals("", journalArticle.getVolume());
	assertEquals("", journalArticle.getStartPage());
	assertEquals(0, journalArticle.getPublicationDate());
	assertEquals("", journalArticle.getJournalName());
}
 
Example #14
Source File: TestNonDepositedFiles.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void checkChains(Structure s) {
	for (Chain chain:s.getChains()) {
		int seqResLength = chain.getSeqResLength();
		int atomLength = chain.getAtomLength();
		System.out.println("chain "+chain.getId()+", atomLength: "+atomLength+", seqResLength: "+seqResLength);
		//assertTrue("atom length ("+atomLength+") should be smaller than seqResLength ("+seqResLength+")",atomLength<=seqResLength);
		System.out.println("seq res groups size: "+chain.getSeqResGroups().size());
	}
}
 
Example #15
Source File: JmolViewerImpl.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setStructure(Structure structure) {
	if (jmolPanel == null) {
		System.err.println("please install Jmol first");
		return;
	}

	setTitle(structure.getPDBCode());

	// actually this is very simple
	// just convert the structure to a PDB file

	String pdb = structure.toPDB();
	//System.out.println(s.isNmr());

	//System.out.println(pdb);
	// Jmol could also read the file directly from your file system
	//viewer.openFile("/Path/To/PDB/1tim.pdb");

	//System.out.println(pdb);
	jmolPanel.openStringInline(pdb);

	// send the PDB file to Jmol.
	// there are also other ways to interact with Jmol, e.g make it directly
	// access the biojava structure object, but they require more
	// code. See the SPICE code repository for how to do this.
}
 
Example #16
Source File: TestMMCIFWriting.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testStructWriting1STP() throws IOException, StructureException {
    Structure s = StructureIO.getStructure("1STP");
    String mmcif = s.toMMCIF();
    assertNotNull(mmcif);
    assertTrue(mmcif.contains("A"));
}
 
Example #17
Source File: MMTFFileReader.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	MMTFFileReader reader = new MMTFFileReader();
	FileParsingParameters params = new FileParsingParameters();
	reader.setFileParsingParameters(params);
	Structure struc = reader.getStructureById("1m4x");
	System.out.println(struc);
}
 
Example #18
Source File: RemotePDPProvider.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{
	RemotePDPProvider me = new RemotePDPProvider(true);

	//System.out.println(scop.getByCategory(ScopCategory.Superfamily));
	SortedSet<String> pdpdomains = me.getPDPDomainNamesForPDB("4HHB");
	System.out.println(pdpdomains);

	AtomCache cache = new AtomCache();
	Structure s = me.getDomain(pdpdomains.first(), cache);
	System.out.println(s);

	me.flushCache();

}
 
Example #19
Source File: TestDifficultMmCIFFiles.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testResidueNumbers() throws IOException, StructureException {
	AtomCache cache = new AtomCache();
	cache.setUseMmCif(true);

	Structure s = cache.getStructure("2PTC");
	Chain c = s.getChainByIndex(0);
	System.out.println(c);
	assertEquals("Wrong first chain",c.getName(),"E");

	Group res = c.getAtomGroup(0);
	ResidueNumber resNum = res.getResidueNumber();

	assertEquals("Groups have wrong chain in resnum",resNum.getChainName(),"E");
}
 
Example #20
Source File: CeSymm.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Analyze the symmetries of the input Atom array using the provided
 * parameters.
 *
 * @param atoms
 *            representative Atom array of the Structure
 * @param param
 *            CeSymmParameters bean
 * @return CeSymmResult
 * @throws StructureException
 */
public static CeSymmResult analyze(Atom[] atoms, CESymmParameters params)
		throws StructureException {

	if (atoms.length < 1)
		throw new IllegalArgumentException("Empty Atom array given.");

	// If the SSE information is needed, we calculate it if the user did not
	if (params.getSSEThreshold() > 0) {
		Structure s = atoms[0].getGroup().getChain().getStructure();
		if (SecStrucTools.getSecStrucInfo(s).isEmpty()) {
			logger.info("Calculating Secondary Structure...");
			SecStrucCalc ssp = new SecStrucCalc();
			ssp.calculate(s, true);
		}
	}

	CeSymmIterative iter = new CeSymmIterative(params);
	CeSymmResult result = iter.execute(atoms);

	if (result.isRefined()) {
		// Optimize the global alignment freely once more (final step)
		if (params.getOptimization() && result.getSymmLevels() > 1) {
			try {
				SymmOptimizer optimizer = new SymmOptimizer(result);
				MultipleAlignment optimized = optimizer.optimize();
				// Set the optimized MultipleAlignment and the axes
				result.setMultipleAlignment(optimized);
			} catch (RefinerFailedException e) {
				logger.info("Final optimization failed:" + e.getMessage());
			}
		}
		result.getMultipleAlignment().getEnsemble()
				.setStructureIdentifiers(result.getRepeatsID());
	}
	return result;
}
 
Example #21
Source File: UnitCellBoundingBox.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void setBb(Structure s, boolean includeHetAtoms, int i) {
	chainBbs[i] = new BoundingBox[numPolyChainsAu];
	List<Chain> polyChains = s.getPolyChains();
	int j = 0;
	for (Chain polyChain : polyChains) {
		chainBbs[i][j] = new BoundingBox(StructureTools.getAllNonHCoordsArray(polyChain, includeHetAtoms));
		j++;
	}
	auBbs[i] = new BoundingBox(chainBbs[i]);
}
 
Example #22
Source File: LocalPDBDirectory.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Structure getStructure(String filename) throws IOException
{
	filename = FileDownloadUtils.expandUserHome(filename);
	File f = new File(filename);
	return getStructure(f);

}
 
Example #23
Source File: TestSubunitClustererExamples.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test internally symmetric: 4E3E bioassembly 1
 */
@Test
public void testInternalSymmetry() throws StructureException, IOException {

	Structure s = StructureIO.getStructure("BIO:4E3E:1");

	SubunitClustererParameters params = new SubunitClustererParameters();
	params.setClustererMethod(SubunitClustererMethod.SEQUENCE);
	params.setSequenceCoverageThreshold(0.8);

	List<SubunitCluster> clusters = SubunitClusterer.cluster(s, params).getClusters();

	// We expect one SEQUENCE cluster with 3 Subunits of length 351
	assertEquals(clusters.size(), 1);
	assertEquals(clusters.get(0).size(), 3);
	assertEquals(clusters.get(0).length(), 351);
	assertEquals(clusters.get(0).getClustererMethod(),
			SubunitClustererMethod.SEQUENCE);

	params.setClustererMethod(SubunitClustererMethod.SEQUENCE_STRUCTURE);
	params.setStructureCoverageThreshold(0.8);
	params.setInternalSymmetry(true);
	params.setRMSDThreshold(3.0);

	clusters = SubunitClusterer.cluster(s, params).getClusters();

	// We expect a single INTERNAL_SYMMETRY cluster with 6 Subunits
	assertEquals(clusters.size(), 1);
	assertEquals(clusters.get(0).size(), 6);
	assertTrue(clusters.get(0).length() < 177);
	assertEquals(clusters.get(0).getClustererMethod(),
			SubunitClustererMethod.STRUCTURE);
}
 
Example #24
Source File: TestMmtfStructureWriter.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test that Biojava can read a file from the file system.
 * @throws IOException
 */
@Test
public void testRead() throws IOException {
	ClassLoader classLoader = getClass().getClassLoader();
	Structure structure = MmtfActions.readFromFile((Paths.get(classLoader.getResource("org/biojava/nbio/structure/io/mmtf/4CUP.mmtf").getPath())));
	assertEquals(structure.getPDBCode(),"4CUP");
	assertEquals(structure.getChains().size(),6);
}
 
Example #25
Source File: FastaAFPChainConverterTest.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testCpSymmetric2() throws IOException,StructureException, CompoundNotFoundException {
	String a = "--vRSLNCTLRDSQQ-KSLVMSG---PYELKALHLQgqdmeq-----QVVFSMSFVQGeesndkiPVALGLKEK-NLYLSSVLKdDKPTLQLESVdpknypkkkmekRFVFNKIEInn--KLEFESAQFpnWYISTSqAENmPVFLGGT----KGgqDITDFTMQFV---";
	String b = "esnDKIPVALGLKEKnLYLSSVLkddKPTLQLESVDpknypkkkmekRFVFNKIEINN-------KLEFESAQFpNWYISTSQA-ENMPVFLGGTkggqd-------ITDFTMQFVvrslNCTLRDSQQ--KSLVMS-GPY-ELKALHLqgqdME--QQVVFSMSFVqge";
	Structure structure = StructureTools.getStructure("31BI");
	AFPChain afpChain = FastaAFPChainConverter.cpFastaToAfpChain(a, b, structure, -101);
	assertEquals("Wrong TM-score", 0.6284, afpChain.getTMScore(), 0.001);
	assertEquals("Wrong RMSD", 2.50569, afpChain.getTotalRmsdOpt(), 0.001);
}
 
Example #26
Source File: TestSubunitExtractor.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Make sure that only aminoacid chains are extracted: 5B2I.
 */
@Test
public void testHistone() throws StructureException, IOException {

	Structure s = StructureIO.getStructure("5B2I");

	List<Subunit> subunits = SubunitExtractor.extractSubunits(s, 5, 0.75, 20);

	// We expect all 8 histone subunits to be returned
	assertEquals(subunits.size(), 8);
	assertEquals(subunits.get(0).size(), 99);
	assertEquals(subunits.get(1).size(), 82);
	assertEquals(subunits.get(2).size(), 106);
}
 
Example #27
Source File: StructureInterface.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Structure getParentStructure() {
	Atom[] firstMol = this.molecules.getFirst();
	if (firstMol.length==0) {
		logger.warn("No atoms found in first molecule, can't get parent Structure");
		return null;
	}
	return firstMol[0].getGroup().getChain().getStructure();
}
 
Example #28
Source File: MyExportListener.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent arg0)
	{
		final JFileChooser fc = new JFileChooser();

		int returnVal = fc.showSaveDialog(null);

		if (returnVal == JFileChooser.APPROVE_OPTION) {
			File file = fc.getSelectedFile();
			//This is where a real application would open the file.
			System.out.println("Exporting PDB file to: " + file.getName());

			Structure s = parent.getStructure();

			try {
				PrintWriter pw = new PrintWriter(new FileWriter(file));
				pw.println(s.toPDB());
				pw.close();
			} catch (IOException e){
			 JOptionPane.showMessageDialog(null,"Could not export file. Exception: " + e.getMessage());
			}


		} else {
			System.out.println("Export command cancelled by user.");
		}


	}
 
Example #29
Source File: ModifiedCompoundSerializationTest.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public List<ModifiedCompound> testXMLSerialization(String pdbId){
	String xml = null;
	ModifiedCompound currentMC = null;
	List<ModifiedCompound> all = new ArrayList<ModifiedCompound>();
	try {

		Structure struc = TmpAtomCache.cache.getStructure(pdbId);

		ProteinModificationIdentifier parser = new ProteinModificationIdentifier();

		for (Chain c : struc.getChains()) {

			parser.identify(c, ProteinModificationRegistry.allModifications());
			Set<ModifiedCompound> mcs = parser.getIdentifiedModifiedCompound();

			for (ModifiedCompound mc : mcs){
				currentMC = mc;
				xml =  doXMLSerialization(mc) ;
				//logger.info( pdbId + " got XML: " + String.format("%n") + xml);
				ModifiedCompound newMC = getModifiedCompoundFromXML(xml);
				String xml2 = doXMLSerialization(newMC);
				Assert.assertEquals(xml, xml2);
				//logger.info(xml2);
				//assertEquals("The two objects are not equal before and after XML serialization" , mc, newMC);
				//logger.info(mc.getDescription());
				//logger.info(newMC.getDescription());
				all.add(mc);
			}
		}
	} catch (Exception e){
		logger.error(e.getMessage(),e);
		logger.error("Error when serializing {}", pdbId);
		logger.error(currentMC.getDescription());
		logger.error(xml, e);
		Assert.fail(e.getMessage());
	}
	xml = null;
	currentMC =null;
	return all;
}
 
Example #30
Source File: TestParseMmCIFFeatures.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testSites()throws IOException, StructureException {

	AtomCache cache = new AtomCache();

	StructureIO.setAtomCache(cache);

	cache.setUseMmCif(true);
	Structure sCif = StructureIO.getStructure("4HHB");

	assertNotNull(sCif);

	// After it has read the file, it should check that expected SITES are present.
	List<Site> sites = sCif.getSites();

	// 4HHB has 6 sites from ligands.
	assertEquals(6, sites.size());

	// Check for each site that it has parsed all residues.
	assertEquals(1, getGroupsInSite(sCif, "AC1"));
	assertEquals(1, getGroupsInSite(sCif, "AC2"));
	assertEquals(16, getGroupsInSite(sCif, "AC3"));
	assertEquals(13, getGroupsInSite(sCif, "AC4"));
	assertEquals(15, getGroupsInSite(sCif, "AC5"));
	assertEquals(7, getGroupsInSite(sCif, "AC6"));

	// Check that struct_site parsing worked, and they have descriptions.
	assertEquals(getDescription(sCif, "AC1"), "BINDING SITE FOR RESIDUE PO4 D 147");
	assertEquals(getDescription(sCif, "AC2"), "BINDING SITE FOR RESIDUE PO4 B 147");
	assertEquals(getDescription(sCif, "AC3"), "BINDING SITE FOR RESIDUE HEM A 142");
	assertEquals(getDescription(sCif, "AC4"), "BINDING SITE FOR RESIDUE HEM B 148");
	assertEquals(getDescription(sCif, "AC5"), "BINDING SITE FOR RESIDUE HEM C 142");
	assertEquals(getDescription(sCif, "AC6"), "BINDING SITE FOR RESIDUE HEM D 148");
}