private ISimpleChemObjectReader getReader(String type, String filename) throws IOException { File input = new File(filename); if (input.isDirectory()) { throw new IOException( "Input path " + filename + " is a directory, not a file"); } switch (type) { case "MOL": return new MDLV2000Reader( new FileReader(input), IChemObjectReader.Mode.RELAXED); case "CML": return new CMLReader(new FileInputStream(input)); case "ML2": return new Mol2Reader(new FileReader(input)); case "PDB": return new PDBReader(new FileReader(input)); } return null; }
private ISimpleChemObjectReader getReader(File file, String extension) throws IOException, CDKException { if (file.isDirectory()) { throw new IOException( "Input path " + file + " is a directory, not a file"); } switch (extension) { case "mol": return new MDLV2000Reader( new FileReader(file), IChemObjectReader.Mode.RELAXED); case "sdf": return new MDLV2000Reader( new FileReader(file)); case "cml": return new CMLReader(new FileInputStream(file)); case "ml2": return new Mol2Reader(new FileReader(file)); case "pdb": PDBReader reader = new PDBReader(new FileReader(file)); reader.getSetting("UseRebondTool").setSetting("false"); // UseRebondTool reader.getSetting("ReadConnectSection").setSetting("true"); // ReadConnectSection return reader; } return null; }
@Test public void molfactoryRoundtripTest() throws Exception { IAtomContainer original = TestMoleculeFactory.makePyrrole(); setCoordinatesToZero(original); StringWriter stringWriter = new StringWriter(); PDBWriter writer = new PDBWriter(stringWriter); writer.writeMolecule(original); writer.close(); String output = stringWriter.toString(); PDBReader reader = new PDBReader(new StringReader(output)); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); reader.close(); IAtomContainer reconstructed = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); Assert.assertEquals(original.getAtomCount(), reconstructed.getAtomCount()); Assert.assertEquals(original.getBondCount(), reconstructed.getBondCount()); } }
PDBReader reader = new PDBReader(stringReader); reader.getSetting("UseRebondTool").setSetting("false"); // UseRebondTool reader.getSetting("ReadConnectSection").setSetting("true"); // ReadConnectSection reader.read(object); reader.close(); stringReader.close(); Assert.assertNotNull(object);
} else if ("ATOM ".equalsIgnoreCase(cCol)) { oAtom = readAtom(cRead, lineLength); oAtom = readAtom(cRead, lineLength); oAtom.setHetAtom(true); if (isProteinStructure) { if (useRebondTool.isSet()) { try { if (!createBondsWithRebondTool(oBP)) { if (useRebondTool.isSet()) createBondsWithRebondTool(molecularStructure); oSet.addAtomContainer(molecularStructure); addBond(molecule, atomFromNumber, atomToNumber); logger.debug("Bonded " + atomFromNumber + " with " + atomToNumber);
@Override public boolean accepts(Class<? extends IChemObject> classObject) { Class<?>[] interfaces = classObject.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (IChemFile.class.equals(interfaces[i])) return true; } if (IChemFile.class.equals(classObject)) return true; Class superClass = classObject.getSuperclass(); if (superClass != null) return this.accepts(superClass); return false; }
private void initIOSettings() { useRebondTool = addSetting(new BooleanIOSetting("UseRebondTool", IOSetting.Importance.LOW, "Should the PDBReader deduce bonding patterns?", "false")); readConnect = addSetting(new BooleanIOSetting("ReadConnectSection", IOSetting.Importance.LOW, "Should the CONECT be read?", "true")); useHetDictionary = addSetting(new BooleanIOSetting("UseHetDictionary", IOSetting.Importance.LOW, "Should the PDBReader use the HETATM dictionary for atom types?", "false")); }
@Test public void testRoundTrip_fractionalCoordinates() throws Exception { StringWriter sWriter = new StringWriter(); PDBWriter writer = new PDBWriter(sWriter); Crystal crystal = new Crystal(); crystal.setA(new Vector3d(0, 1, 0)); crystal.setB(new Vector3d(1, 0, 0)); crystal.setC(new Vector3d(0, 0, 2)); IAtom atom = new Atom("C"); atom.setFractionalPoint3d(new Point3d(0.1, 0.1, 0.3)); crystal.addAtom(atom); writer.write(crystal); writer.close(); String output = sWriter.toString(); Assert.assertNotNull(output); Assert.assertTrue(output.length() > 0); PDBReader reader = new PDBReader(); ChemFile chemFile = (ChemFile) reader.read(new ChemFile()); reader.close(); Assert.assertNotNull(chemFile); Assert.assertEquals(1, chemFile.getChemSequenceCount()); IChemSequence sequence = chemFile.getChemSequence(0); Assert.assertEquals(1, sequence.getChemModelCount()); IChemModel chemModel = sequence.getChemModel(0); Assert.assertNotNull(chemModel); // can't do further testing as the PDBReader does not read // Crystal structures :( }
} else if ("ATOM ".equalsIgnoreCase(cCol)) { oAtom = readAtom(cRead, lineLength); oAtom = readAtom(cRead, lineLength); oAtom.setHetAtom(true); if (isProteinStructure) { if (useRebondTool.isSet()) { try { if (!createBondsWithRebondTool(oBP)) { if (useRebondTool.isSet()) createBondsWithRebondTool(molecularStructure); oSet.addAtomContainer(molecularStructure); addBond(molecule, atomFromNumber, atomToNumber); logger.debug("Bonded " + atomFromNumber + " with " + atomToNumber);
@Override public boolean accepts(Class<? extends IChemObject> classObject) { Class<?>[] interfaces = classObject.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (IChemFile.class.equals(interfaces[i])) return true; } if (IChemFile.class.equals(classObject)) return true; Class superClass = classObject.getSuperclass(); if (superClass != null) return this.accepts(superClass); return false; }
private void initIOSettings() { useRebondTool = addSetting(new BooleanIOSetting("UseRebondTool", IOSetting.Importance.LOW, "Should the PDBReader deduce bonding patterns?", "false")); readConnect = addSetting(new BooleanIOSetting("ReadConnectSection", IOSetting.Importance.LOW, "Should the CONECT be read?", "true")); useHetDictionary = addSetting(new BooleanIOSetting("UseHetDictionary", IOSetting.Importance.LOW, "Should the PDBReader use the HETATM dictionary for atom types?", "false")); }
public IChemFile getChemFile(String filename, boolean useRebond) throws Exception { InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); return getChemFile(new PDBReader(ins), useRebond); }
@Test public void testRoundTrip() throws Exception { StringWriter sWriter = new StringWriter(); PDBWriter writer = new PDBWriter(sWriter); ICrystal crystal = builder.newInstance(ICrystal.class); crystal.setA(new Vector3d(0, 1, 0)); crystal.setB(new Vector3d(1, 0, 0)); crystal.setC(new Vector3d(0, 0, 2)); IAtom atom = builder.newInstance(IAtom.class, "C"); atom.setPoint3d(new Point3d(0.1, 0.1, 0.3)); crystal.addAtom(atom); writer.write(crystal); writer.close(); String output = sWriter.toString(); Assert.assertNotNull(output); Assert.assertTrue(output.length() > 0); PDBReader reader = new PDBReader(); ChemFile chemFile = (ChemFile) reader.read(new ChemFile()); reader.close(); Assert.assertNotNull(chemFile); Assert.assertEquals(1, chemFile.getChemSequenceCount()); IChemSequence sequence = chemFile.getChemSequence(0); Assert.assertEquals(1, sequence.getChemModelCount()); IChemModel chemModel = sequence.getChemModel(0); Assert.assertNotNull(chemModel); // can't do further testing as the PDBReader does not read // Crystal structures :( }
public IChemFile getChemFileFromString(String data) throws Exception { StringReader stringReader = new StringReader(data); PDBReader reader = new PDBReader(stringReader); Assert.assertNotNull(reader); return getChemFile(reader); }
@BeforeClass public static void setup() throws Exception { setSimpleChemObjectReader(new PDBReader(), "data/pdb/coffeine.pdb"); }
@Test public void testMOL2files() throws Exception { final String DIRNAME = "data/mol2/"; String[] testFiles = {"fromWebsite.mol2",}; int tested = 0; int failed = 0; ISimpleChemObjectReader reader = new PDBReader(); for (String testFile : testFiles) { TestResults results = testFile(DIRNAME, testFile, reader); tested += results.tested; failed += results.failed; } Assert.assertEquals("Could not match all atom types!", tested, (tested - failed)); }
@Test public void testASNfiles() throws Exception { final String DIRNAME = "data/asn/pubchem/"; String[] testFiles = {"cid1.asn",}; int tested = 0; int failed = 0; ISimpleChemObjectReader reader = new PDBReader(); for (String testFile : testFiles) { TestResults results = testFile(DIRNAME, testFile, reader); tested += results.tested; failed += results.failed; } Assert.assertEquals("Could not match all atom types!", tested, (tested - failed)); }
@Ignore @Test public void testPDBfiles() throws Exception { final String DIRNAME = "data/pdb/"; String[] testFiles = {"114D.pdb", "1CRN.pdb", "1D66.pdb", "1IHA.pdb", "1PN8.pdb",}; int tested = 0; int failed = 0; ISimpleChemObjectReader reader = new PDBReader(); for (String testFile : testFiles) { TestResults results = testFile(DIRNAME, testFile, reader); tested += results.tested; failed += results.failed; } Assert.assertEquals("Could not match all atom types!", tested, (tested - failed)); }