String sg = crystal.getSpaceGroup(); if ("P 2_1 2_1 2_1".equals(sg)) { writeln("P 21 21 21 (1)"); writeVector3d(crystal.getA()); writeVector3d(crystal.getB()); writeVector3d(crystal.getC()); int noatoms = crystal.getAtomCount(); write(Integer.toString(noatoms)); writeln(""); IAtom atom = crystal.getAtom(i); write(atom.getSymbol()); write(":");
crystal.setA(axes[0]); crystal.setB(axes[1]); crystal.setC(axes[2]); } else if (command.equalsIgnoreCase("ZERR")) { } else if (command.equalsIgnoreCase("LATT")) { crystal.setSpaceGroup(spacegroup); } else if (command.equalsIgnoreCase(" ")) { logger.debug("Disrgarding line assumed to be added by PLATON: " + line); IAtom atom = crystal.getBuilder().newInstance(IAtom.class, atype); atom.setFractionalPoint3d(new Point3d(frac[0], frac[1], frac[2])); crystal.addAtom(atom); logger.debug("Atom added: ", atom);
private CMLMolecule cdkCrystalToCMLMolecule(ICrystal crystal, boolean setIDs) { CMLMolecule molecule = cdkAtomContainerToCMLMolecule(crystal, false, false); CMLCrystal cmlCrystal = new CMLCrystal(); if (useCMLIDs && setIDs) { IDCreator.createIDs(crystal); } if (crystal.getID() != null && !crystal.getID().equals("")) cmlCrystal.setId(crystal.getID()); this.checkPrefix(cmlCrystal); cmlCrystal.setZ(crystal.getZ()); double[] params = CrystalGeometryTools.cartesianToNotional(crystal.getA(), crystal.getB(), crystal.getC()); logger.debug("Number of cell params: ", params.length); cmlCrystal.setCellParameters(params); molecule.appendChild(cmlCrystal); return molecule; }
private void possiblySetCellParams(double a, double b, double c, double alpha, double beta, double gamma) { if (a != 0.0 && b != 0.0 && c != 0.0 && alpha != 0.0 && beta != 0.0 && gamma != 0.0) { logger.info("Found and set crystal cell parameters"); Vector3d[] axes = CrystalGeometryTools.notionalToCartesian(a, b, c, alpha, beta, gamma); crystal.setA(axes[0]); crystal.setB(axes[1]); crystal.setC(axes[2]); } }
/** * Creates Cartesian coordinates for all Atoms in the Crystal. */ public static void fractionalToCartesian(ICrystal crystal) { Iterator<IAtom> atoms = crystal.atoms().iterator(); Vector3d aAxis = crystal.getA(); Vector3d bAxis = crystal.getB(); Vector3d cAxis = crystal.getC(); while (atoms.hasNext()) { IAtom atom = atoms.next(); Point3d fracPoint = atom.getFractionalPoint3d(); if (fracPoint != null) { atom.setPoint3d(fractionalToCartesian(aAxis, bAxis, cAxis, fracPoint)); } } } }
line = input.readLine(); logger.debug((lineNumber++) + ": ", line); crystal.setSpaceGroup(line); logger.debug((lineNumber++) + ": ", line); axis.z = FortranFormat.atof(line); crystal.setA(axis); axis = new Vector3d(); logger.debug("parsing B: "); logger.debug((lineNumber++) + ": ", line); axis.z = FortranFormat.atof(line); crystal.setB(axis); axis = new Vector3d(); logger.debug("parsing C: "); logger.debug((lineNumber++) + ": ", line); axis.z = FortranFormat.atof(line); crystal.setC(axis); logger.debug("Crystal: ", crystal); a = crystal.getA(); b = crystal.getB(); c = crystal.getC(); logger.debug((lineNumber++) + ": ", line); int Z = Integer.parseInt(line); crystal.setZ(Z); crystal.addAtom(atom);
Assert.assertEquals(4, crystal.getZ().intValue()); Assert.assertEquals("Fm3m", crystal.getSpaceGroup()); Assert.assertEquals(2, crystal.getAtomCount()); Vector3d aaxis = crystal.getA(); Assert.assertEquals(4.5, aaxis.x, 0.1); Assert.assertEquals(0.0, aaxis.y, 0.1); Assert.assertEquals(0.0, aaxis.z, 0.1); Vector3d baxis = crystal.getB(); Assert.assertEquals(0.0, baxis.x, 0.1); Assert.assertEquals(4.5, baxis.y, 0.1); Assert.assertEquals(0.0, baxis.z, 0.1); Vector3d caxis = crystal.getC(); Assert.assertEquals(0.0, caxis.x, 0.1); Assert.assertEquals(0.0, caxis.y, 0.1);
private void writeCrystal(ICrystal crystal) { Object title = crystal.getTitle(); if (title != null && title.toString().trim().length() > 0) { writeln("TITL " + title.toString().trim()); writeln("TITL Produced with CDK (http://cdk.sf.net/)"); Vector3d a = crystal.getA(); Vector3d b = crystal.getB(); Vector3d c = crystal.getC(); double alength = a.length(); double blength = b.length(); write(format.reset("%8.4f").format(beta) + " "); writeln(format.reset("%8.4f").format(gamma) + ""); writeln("ZERR " + format.reset("%1.5f").format((double) crystal.getZ()) + " 0.01000 0.01000 0.01000 0.0100 0.0100 0.0100"); String spaceGroup = crystal.getSpaceGroup(); if ("P1".equals(spaceGroup)) { writeln("LATT -1"); writeln("UNIT " + elemCounts); for (int i = 0; i < crystal.getAtomCount(); i++) { IAtom atom = crystal.getAtom(i); Point3d cartCoord = atom.getPoint3d(); Point3d fracCoord = CrystalGeometryTools.cartesianToFractional(a, b, c, cartCoord);
Assert.assertEquals(42, crystal.getAtomCount()); Assert.assertEquals(1, crystal.getZ().intValue()); org.openscience.cdk.interfaces.IAtom atom = crystal.getAtom(0); Assert.assertNotNull(atom); Assert.assertEquals("O", atom.getSymbol()); Vector3d a = crystal.getA(); Assert.assertEquals(7.971030, a.x, 0.000001); Assert.assertEquals(0.0, a.y, 0.000001); Assert.assertEquals(0.0, a.z, 0.000001); Vector3d b = crystal.getB(); Assert.assertEquals(0.0, b.x, 0.000001); Assert.assertEquals(18.772200, b.y, 0.000001); Assert.assertEquals(0.0, b.z, 0.000001); Vector3d c = crystal.getC(); Assert.assertEquals(0.0, c.x, 0.000001); Assert.assertEquals(0.0, c.y, 0.000001);
IAtom atom = crystal.getBuilder().newInstance(IAtom.class, "C"); Point3d frac = new Point3d(); Point3d real = new Point3d(); Vector3d a = crystal.getA(); Vector3d b = crystal.getB(); Vector3d c = crystal.getC(); frac = CrystalGeometryTools.cartesianToFractional(a, b, c, real); atom.setFractionalPoint3d(frac); crystal.addAtom(atom);
((ICrystal) currentMolecule).setSpaceGroup(sg); } else if (xpath.toString().endsWith("floatArray/") && (elementTitle.equals("a") || elementTitle.equals("b") || elementTitle.equals("c"))) { if (st.countTokens() > 2) { if (elementTitle.equals("a")) { ((ICrystal) currentMolecule).setA(new Vector3d(Double.parseDouble(st.nextToken()), Double .parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()))); } else if (elementTitle.equals("b")) { ((ICrystal) currentMolecule).setB(new Vector3d(Double.parseDouble(st.nextToken()), Double .parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()))); } else if (elementTitle.equals("c")) { ((ICrystal) currentMolecule).setC(new Vector3d(Double.parseDouble(st.nextToken()), Double .parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())));
@Test() public void cod1100784CellLengths() throws IOException, CDKException { InputStream in = getClass().getResourceAsStream("1100784.cif"); CIFReader cifReader = new CIFReader(in); IChemFile chemFile = cifReader.read(new ChemFile()); ICrystal crystal = chemFile.getChemSequence(0).getChemModel(0).getCrystal(); Assert.assertTrue( java.lang.Math.abs(crystal.getA().length() - 10.9754) < 1E-5 ); Assert.assertTrue( java.lang.Math.abs(crystal.getB().length() - 11.4045) < 1E-5 ); Assert.assertTrue( java.lang.Math.abs(crystal.getC().length() - 12.9314) < 1E-5 ); cifReader.close(); }
@Test public void testCrystal() { ICrystal crystal = new Crystal(); Assert.assertNotNull(crystal); Assert.assertEquals(0, crystal.getAtomCount()); Assert.assertEquals(0, crystal.getBondCount()); }
Assert.assertEquals(4 * 42, crystal.getAtomCount()); Assert.assertTrue(GeometryUtil.has3DCoordinates(crystal)); Vector3d a = crystal.getA(); Assert.assertTrue(a.x != 0.0); Vector3d b = crystal.getB(); Assert.assertTrue(b.y != 0.0); Vector3d c = crystal.getC(); Assert.assertTrue(c.z != 0.0);
@Test public void testCMLCrystal() throws Exception { StringWriter writer = new StringWriter(); ICrystal crystal = new Crystal(); IAtom silicon = new Atom("Si"); silicon.setFractionalPoint3d(new Point3d(0.0, 0.0, 0.0)); crystal.addAtom(silicon); crystal.setA(new Vector3d(1.5, 0.0, 0.0)); crystal.setB(new Vector3d(0.0, 2.0, 0.0)); crystal.setC(new Vector3d(0.0, 0.0, 1.5)); CMLWriter cmlWriter = new CMLWriter(writer); cmlWriter.write(crystal); cmlWriter.close(); String cmlContent = writer.toString(); logger.debug("****************************** testCMLCrystal()"); logger.debug(cmlContent); logger.debug("******************************"); Assert.assertTrue(cmlContent.indexOf("</crystal>") != -1); // the cystal info has to be present Assert.assertTrue(cmlContent.indexOf("<atom") != -1); // an Atom has to be present }
@Test @Override public void testAdd_IAtomContainer() { ICrystal crystal = (ICrystal) newChemObject(); IAtomContainer acetone = crystal.getBuilder().newInstance(IAtomContainer.class); IAtom c1 = crystal.getBuilder().newInstance(IAtom.class, "C"); IAtom c2 = crystal.getBuilder().newInstance(IAtom.class, "C"); IAtom o = crystal.getBuilder().newInstance(IAtom.class, "O"); IAtom c3 = crystal.getBuilder().newInstance(IAtom.class, "C"); acetone.addAtom(c1); acetone.addAtom(c2); acetone.addAtom(c3); acetone.addAtom(o); IBond b1 = crystal.getBuilder().newInstance(IBond.class, c1, c2, IBond.Order.SINGLE); IBond b2 = crystal.getBuilder().newInstance(IBond.class, c1, o, IBond.Order.DOUBLE); IBond b3 = crystal.getBuilder().newInstance(IBond.class, c1, c3, IBond.Order.SINGLE); acetone.addBond(b1); acetone.addBond(b2); acetone.addBond(b3); crystal.add(acetone); Assert.assertEquals(4, crystal.getAtomCount()); Assert.assertEquals(3, crystal.getBondCount()); }
@Test @Override public void testAddAtom_IAtom() { ICrystal crystal = (ICrystal) newChemObject(); IAtom c1 = crystal.getBuilder().newInstance(IAtom.class, "C"); crystal.addAtom(c1); Assert.assertEquals(1, crystal.getAtomCount()); }
@Test public void testClone_Axes() throws Exception { ICrystal crystal1 = (ICrystal) newChemObject(); Vector3d axes = new Vector3d(1.0, 2.0, 3.0); crystal1.setA(axes); ICrystal crystal2 = (ICrystal) crystal1.clone(); // test cloning of axes crystal1.getA().x = 5.0; Assert.assertEquals(1.0, crystal2.getA().x, 0.001); }
@Test public void testAceticAcid() throws Exception { String filename = "data/pmp/aceticacid.pmp"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); PMPReader reader = new PMPReader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); reader.close(); Assert.assertNotNull(chemFile); Assert.assertEquals(1, chemFile.getChemSequenceCount()); IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(1, seq.getChemModelCount()); IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); ICrystal crystal = model.getCrystal(); Assert.assertNotNull(crystal); Assert.assertEquals(32, crystal.getAtomCount()); Assert.assertEquals(28, crystal.getBondCount()); Assert.assertEquals("O", crystal.getAtom(6).getSymbol()); Assert.assertEquals(1.4921997, crystal.getAtom(6).getPoint3d().x, 0.00001); Assert.assertEquals("O", crystal.getAtom(7).getSymbol()); Assert.assertEquals(1.4922556, crystal.getAtom(7).getPoint3d().x, 0.00001); }