/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import java.io.IOException;
import chemaxon.formats.MolExporter;
import chemaxon.struc.*;
/**
* Example class for structure manipulation. Creates CO
*
* @author Andras Volford, Miklos Vargyas
*
*/
public class BuildMoleculeCO {
public static void main(String[] args) throws IOException{
// create an empty Molecule
Molecule m = new Molecule();
// create the Carbon atom
MolAtom a1 = new MolAtom(6);
// and add it to the molecule
m.add(a1);
// create the Oxygen atom
MolAtom a2 = new MolAtom(8);
// and add it to the molecule
m.add(a2);
System.out.println(MolExporter.exportToFormat(m,"smiles"));
// this prints C.O as no bond has been defined yet
// create a bond between atoms, bond order
MolBond b = new MolBond(a1, a2, 2);
m.add(b);
System.out.println(MolExporter.exportToFormat(m,"smiles"));
// this prints C=O
}
}
Build water molecule
package chemaxon.examples.strucrep
import chemaxon.struc.*;
/**
* Example class for structure manipulation. Creates water.
*
* @author Andras Volford
*
*/
public class BuildMoleculeWater {
public static void main(String[] args) {
// create an empty Molecule
Molecule m = new Molecule();
// create the Carbon atom
MolAtom a1 = new MolAtom(8);
// and add it to the molecule
m.add(a1);
// create the Hydrogen atom
MolAtom a2 = new MolAtom(1);
// and add it to the molecule
m.add(a2);
// create the Hydrogen atom
MolAtom a3 = new MolAtom(1);
// and add it to the molecule
m.add(a3);
System.out.println(m.toFormat("smiles"));
// this prints [H+].[H+].O as no bond has been defined yet
// create a bond between atoms, bond order
MolBond b1 = new MolBond(a1, a2, 1);
m.add(b1);
MolBond b2 = new MolBond(a1, a3, 1);
m.add(b2);
System.out.println(m.toFormat("smiles"));
// this prints water
}
}
BuildMoleculeEthylene.java
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import java.io.IOException;
import chemaxon.formats.MolExporter;
import chemaxon.calculations.clean.Cleaner;
import chemaxon.struc.*;
/**
* Example class for structure manipulation. Creates ethylene C/C=C=/C
* atom by atom.
*
* @author Andras Volford, Miklos Vargyas
*/
public class BuildMoleculeEthylene {
public static void main(String[] args) throws IOException{
// create an empty Molecule
Molecule m = new Molecule();
// create a Carbon atom
MolAtom a1 = new MolAtom(6);
// and add it to the molecule
m.add(a1);
// create another Carbon atom
MolAtom a2 = new MolAtom(6);
// and add it to the molecule
m.add(a2);
// create a bond between atoms, bond order
MolBond b = new MolBond(a1, a2, 2);
m.add(b);
System.out.println(MolExporter.exportToFormat(m,"smiles"));
// this prints C=C
// add ligands
MolAtom l1 = new MolAtom(6);
MolAtom l2 = new MolAtom(6);
m.add(l1);
m.add(l2);
m.add(new MolBond(a1, l1));
m.add(new MolBond(a2, l2));
System.out.println(MolExporter.exportToFormat(m,"smiles"));
System.out.println(MolExporter.exportToFormat(m,"mol"));
// generate 2D coordinates
Cleaner.clean(m, 2, null);
System.out.println(MolExporter.exportToFormat(m, "mol"));
// CIS/TRANS information is not defined, the bond is wiggly
b = m.getBond(0);
System.out.println("cis=" + MolBond.CIS );
System.out.println("trans=" + MolBond.TRANS );
System.out.println("stereo flag before setting: " + (b.getFlags() & MolBond.STEREO_MASK));
// set bond to CIS
b.setFlags(MolBond.CIS, MolBond.STEREO_MASK);
System.out.println("stereo flag after setting: " + (b.getFlags() & MolBond.STEREO_MASK));
System.out.println(MolExporter.exportToFormat(m, "mol"));
// render again in 2D
System.out.println("Cleaned again");
Cleaner.clean(m, 2, null);
System.out.println("stereo flag: " + (b.getFlags() & MolBond.STEREO_MASK));
System.out.println(MolExporter.exportToFormat(m, "mol"));
m.setDim(0);
b.setFlags(MolBond.CIS, MolBond.STEREO_MASK);
System.out.println("stereo flag after setting: " + (b.getFlags() & MolBond.STEREO_MASK));
System.out.println(MolExporter.exportToFormat(m, "mol"));
// render again in 2D
System.out.println("Cleaned the 3rd time after setdim(0)");
Cleaner.clean(m, 2, null);
System.out.println("stereo flag: " + (b.getFlags() & MolBond.STEREO_MASK));
System.out.println(MolExporter.exportToFormat(m, "mol"));
}
}
BuildMoleculeEthyleneStereo.java
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import java.io.IOException;
import chemaxon.formats.MolExporter;
import chemaxon.calculations.clean.Cleaner;
import chemaxon.struc.*;
/**
* Example class for structure manipulation. Creates ethylene C/C=C=/C
* atom by atom.
*
* @author Andras Volford, Miklos Vargyas
*/
public class BuildMoleculeEthyleneStereo {
public static void main(String[] args) throws IOException {
// create an empty Molecule
Molecule m = new Molecule();
// create a Carbon atom
MolAtom a1 = new MolAtom(6);
// and add it to the molecule
m.add(a1);
// create anoter Carbon atom
MolAtom a2 = new MolAtom(6);
// and add it to the molecule
m.add(a2);
// create a bond between atoms, bond order
MolBond b = new MolBond(a1, a2, 2);
m.add(b);
System.out.println(MolExporter.exportToFormat(m, "smiles"));
// this prints C=C
// add ligands
MolAtom l1 = new MolAtom(6);
MolAtom l2 = new MolAtom(6);
m.add(l1);
m.add(l2);
m.add(new MolBond(a1, l1));
m.add(new MolBond(a2, l2));
System.out.println(MolExporter.exportToFormat(m, "smiles"));
System.out.println(MolExporter.exportToFormat(m, "mol"));
// generate 2D coordinates
Cleaner.clean(m, 2, null);
System.out.println(m.toFormat(MolExporter.exportToFormat(m, "mol"));
}
}
MoleculeAtoms.java
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import java.io.IOException;
import chemaxon.formats.MolFormatException;
import chemaxon.formats.MolImporter;
import chemaxon.struc.Molecule;
import chemaxon.struc.MolAtom;
import chemaxon.struc.MolBond;
/**
* Example class to demonstrate how to access atoms and bonds
* of the molecule.
*
* @author Andras Volford, Miklos Vargyas
*
*/
public class MoleculeAtoms {
public static void main(String[] args) {
String filename = args[0];
try {
// create a molecule importer for the given file
MolImporter mi = new MolImporter(filename);
// read the first molecule from the file
Molecule m = mi.read();
while (m != null) {
printAtoms(m);
printBonds(m);
// read the next molecule from the input file
m = mi.read();
}
mi.close();
}
catch (MolFormatException e) {
System.err.println("Molecule format not recognised.");
}
catch (IOException e) {
System.err.println("I/O error:" + e);
}
}
private static void printAtoms( Molecule m ) {
m.calcHybridization();
System.out.println("Atoms in the molecule\natomic number\tcharge\thybridisation");
for (int i = 0; i < m.getAtomCount(); i++) {
MolAtom a = m.getAtom(i);
System.out.println( i + "th atom: " + a.getAtno() + "\t\t"
+ a.getCharge() + "\t"
+ a.getHybridizationState());
}
}
private static void printBonds( Molecule m ) {
System.out.println("Bonds in the molecule\nbond order\tcoodinate");
for (int i = 0; i < m.getBondCount(); i++) {
MolBond b = m.getBond(i);
System.out.println( b.getType() + "\t\t" + b.isCoordinate() + " "
+ m.indexOf( b.getAtom1()) + "-" + m.indexOf( b.getAtom2()));
}
}
}
MoleculeIterators.java
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import java.io.IOException;
import chemaxon.formats.MolFormatException;
import chemaxon.formats.MolImporter;
import chemaxon.struc.Molecule;
import chemaxon.struc.MolAtom;
import chemaxon.struc.MolBond;
import chemaxon.util.iterator.IteratorFactory;
import chemaxon.util.iterator.IteratorFactory.AtomIterator;
import chemaxon.util.iterator.IteratorFactory.BondIterator;
/**
* Example class to demonstrate how to access atoms and bonds
* of the molecule using Iterators.
*
* @author Andras Volford, Miklos Vargyas
*
*/
public class MoleculeIterators {
public static void main(String[] args) {
String filename = args[0];
try {
// create a molecule importer for the given file
MolImporter mi = new MolImporter(filename);
// read the first molecule from the file
Molecule m = mi.read();
while (m != null) {
IteratorFactory itFac = new IteratorFactory(m,
IteratorFactory.INCLUDE_CHEMICAL_ATOMS_ONLY,
IteratorFactory.REPLACE_COORDINATE_BONDS );
printAtoms(itFac,m);
printBonds(itFac,m);
// read the next molecule from the input file
m = mi.read();
}
mi.close();
}
catch (MolFormatException e) {
System.err.println("Molecule format not recognised.");
}
catch (IOException e) {
System.err.println("I/O error:" + e);
}
}
private static void printAtoms( IteratorFactory itFac, Molecule m ) {
AtomIterator ai = itFac.createAtomIterator();
System.out.println("Atoms in the molecule\natomic number\tcharge");
while (ai.hasNext()) {
MolAtom a = ai.next();
System.out.println( a.getAtno() + "\t\t" + a.getCharge() );
}
}
private static void printBonds( IteratorFactory itFac, Molecule m ) {
BondIterator bi = itFac.createBondIterator();
System.out.println("Bonds in the molecule\nbond order\tcoodinate");
while (bi.hasNext()) {
MolBond b = bi.next();
System.out.println( b.getType() + "\t\t" + b.isCoordinate()
+ " " + m.indexOf(b.getAtom1()) + "-"
+ m.indexOf(b.getAtom2()));
}
}
}
ReadMoleculeFile.java
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import java.io.IOException;
import chemaxon.formats.MolFormatException;
import chemaxon.formats.MolImporter;
import chemaxon.struc.Molecule;
/**
* Example class for molecule import.
*
* @author Andras Volford, Miklos Vargyas
*
*/
public class ReadMoleculeFile {
public static void main(String[] args) {
String filename = args[0];
try {
// create a molecule importer for the given file
MolImporter mi = new MolImporter(filename);
// read the first molecule from the file
Molecule m = mi.read();
while (m != null) {
printProperties( m );
// read the next molecule from the input file
m = mi.read();
}
mi.close();
}
catch (MolFormatException e) {
System.err.println("Molecule format not recognised.");
}
catch (IOException e) {
System.err.println("I/O error:" + e);
}
}
private static void printProperties( Molecule m ) {
System.out.println( "\nMolecule " + m.getName() );
int nProps = m.getPropertyCount();
for ( int i = 0; i < nProps; i++ ) {
String propKey = m.getPropertyKey( i );
String propValue = m.getProperty( propKey );
System.out.println( propKey + " = " + propValue );
}
}
}
ReadMoleculeString.java
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import chemaxon.formats.MolImporter;
import chemaxon.formats.MolFormatException;
import chemaxon.struc.Molecule;
/**
* Simple example of building a molecule from a SMILES string.
*
* @author Andras Volford, Miklos Vargyas
*
*/
public class ReadMoleculeString {
public static void main(String[] args) {
try {
String smiles = "CC>>CC";
Molecule m = MolImporter.importMol(smiles);
System.out.println(m.getAtomCount());
System.out.println(m.toFormat("mol"));
}
catch (MolFormatException e) {
System.err.println("Format not recognised.");
}
}
}
CisTransExample.java
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import java.io.IOException;
import chemaxon.struc.Molecule;
import chemaxon.struc.MolBond;
import chemaxon.struc.CNode;
import chemaxon.struc.StereoConstants;
import chemaxon.formats.MolImporter;
/**
* Example to get double bond stereo information of double bonds.
* Usage:
* java CisTransExample filename
*
* @version 5.1 04/24/2008
* @since Marvin 5.1
* @author Andras Volford
*/
public class CisTransExample {
/**
* Main method.
* @param args command line arguments (filename)
*/
public static void main(String[] args) throws IOException {
if(args.length < 1) {
System.err.println("Usage: java CisTransTest filename");
System.exit(0);
}
// create importer for the file argument
String s = (String)args[0];
MolImporter molimp = new MolImporter(s);
// store the imported molecules in m
Molecule m = new Molecule();
// counter for molecules
int n = 0;
while(molimp.read(m)){ // read molecules from the file
++n; // increment counter
System.err.println("mol "+n);
// calculate double bond stereo for every double bond
// which have at least one ligand on each node of the double bond
for (int i=0; i<m.getBondCount(); i++){
MolBond b = m.getBond(i);
if (b.getType() == 2){
// get the default frame
CNode c1 = b.getCTAtom1();
CNode c2 = b.getNode1();
CNode c3 = b.getNode2();
CNode c4 = b.getCTAtom4();
if (c1 != null && c4 != null){
// cis/trans stereo for the default frame
int ct = m.getStereo2(b, c1, c4, true);
System.out.println(m.indexOf(c1)+"-"+
m.indexOf(c2)+"="+m.indexOf(c3)+"-"+
m.indexOf(c4)+" "+
((ct == MolBond.CIS) ? "CIS" :
(ct == MolBond.TRANS) ? "TRANS" :
(ct == (MolBond.TRANS|MolBond.CIS)) ?
"CIS|TRANS" : (""+ct) )+
(((ct & StereoConstants.CTUNSPEC) != 0) ?
"CTUNSPEC" : " ") );
// E/Z stereo
ct = m.getStereo2(b);
System.out.println("E/Z "+
m.indexOf(c2)+"="+m.indexOf(c3)+" "+
((ct == MolBond.CIS) ? "Z" :
(ct == MolBond.TRANS) ? "E" : ""+ct )+
(((ct & StereoConstants.CTUNSPEC) != 0) ?
"CTUNSPEC" : "") );
}
}
}
}
}
}
ParityExample.java
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import java.io.IOException;
import chemaxon.struc.Molecule;
import chemaxon.formats.MolImporter;
import chemaxon.struc.StereoConstants;
public class ParityExample {
/**
* Example to get the parity and chirality of the atoms.
* @param args command line arguments
* @throws java.io.IOException
*
* @version 5.1 04/24/2008
* @since Marvin 5.1
* @author Andras Volford
*/
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("Usage: java ParityExample filename");
System.exit(0);
}
// create importer for the file argument
String s = (String) args[0];
MolImporter molimp = new MolImporter(s);
// store the imported molecules in m
Molecule m = new Molecule();
// counter for molecules
int n = 0;
while (molimp.read(m)) { // read molecules from the file
++n; // increment counter
System.out.println("mol " + n);
// print parity information followed by the chirality
for (int i = 0; i < m.getAtomCount(); i++) {
int c = m.getChirality(i);
System.out.println(
i + " Parity " + m.getParity(i) +
" Chirality " +
((c == StereoConstants.CHIRALITY_R) ? "R" :
(c == StereoConstants.CHIRALITY_S) ? "S" :
("" + c)) + " " + c);
}
}
}
}
ExplicitHToChiralCenter.java
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
*/
import java.io.IOException;
import chemaxon.struc.Molecule;
import chemaxon.struc.MolAtom;
import chemaxon.formats.MolImporter;
import chemaxon.struc.StereoConstants;
public class ExplicitHToChiralCenter {
/**
* Example to add Explicit H to Chiral centers only.
* @param args command line arguments
* @throws java.io.IOException
*
* @version 5.1 04/24/2008
* @since Marvin 5.1
* @author Andras Volford
*/
// ODD and EVEN parity values
static int ODD = StereoConstants.PARITY_ODD;
static int EVEN = StereoConstants.PARITY_EVEN;
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("Usage: java ExplicitHToChiralCenter
filename");
System.exit(0);
}
// create importer for the file argument
String s = (String) args[0];
MolImporter molimp = new MolImporter(s);
// store the imported molecules in m
Molecule m = new Molecule();
while (molimp.read(m)) { // read molecules from the file
int ac = m.getAtomCount();
// Atoms with odd or even parity
MolAtom[] t = new MolAtom[ac];
int n = 0;
for (int i = 0; i < ac; i++){
int p = m.getParity(i);
boolean add = p == ODD || p == EVEN;
// if the atom has ODD or EVEN parity
if (add) {
t[n++] = m.getAtom(i);
}
}
// reduce atom array
MolAtom[] a = new MolAtom[n];
System.arraycopy(t, 0, a, 0, n);
// add explicit H
m.addExplicitHydrogens(0, a);
if (m.getDim() != 2)
m.clean(2, null);
// write the result
System.out.print(m.toFormat("sdf"));
}
}
}
Build R-group
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
* This software is the confidential and proprietary information of
* ChemAxon. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with ChemAxon.
*
*/
package chemaxon.examples.strucrep;
import java.io.IOException;
import chemaxon.calculations.clean.Cleaner;
import chemaxon.formats.MolExporter;
import chemaxon.formats.MolImporter;
import chemaxon.struc.MolAtom;
import chemaxon.struc.MolBond;
import chemaxon.struc.Molecule;
import chemaxon.struc.RgMolecule;
/**
* Example class. Creates a basic RgMolecule.
*
* @author Janos Kendi
*
*/
public class BuildRgMolecule {
public static void main(String[] args) throws IOException {
// Create the root of the RgMolecule
Molecule root = MolImporter.importMol("C1CCCCC1");
// Create Rgroups
MolAtom r1 = new MolAtom(MolAtom.RGROUP);
r1.setRgroup(1);
root.add(r1);
root.add(new MolBond(r1, root.getAtom(0)));
MolAtom r2 = new MolAtom(MolAtom.RGROUP);
r2.setRgroup(2);
root.add(r2);
root.add(new MolBond(r2, root.getAtom(5)));
// Create the RgMolecule
RgMolecule rgMol = new RgMolecule();
rgMol.setRoot(root);
// Add Rgroup definitions
Molecule rg = MolImporter.importMol("O");
rg.getAtom(0).addRgroupAttachmentPoint(1, 1);
rgMol.addRgroup(1, rg);
rg = MolImporter.importMol("N");
rg.getAtom(0).addRgroupAttachmentPoint(1, 2);
rgMol.addRgroup(1, rg);
rg = MolImporter.importMol("CC");
rg.getAtom(0).addRgroupAttachmentPoint(1, 1);
rgMol.addRgroup(2, rg);
Cleaner.clean(rgMol, 2, null);
System.out.println(MolExporter.exportToFormat(rgMol, "mrv:P"));
}
}
Build a Reaction
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
* This software is the confidential and proprietary information of
* ChemAxon. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with ChemAxon.
*
*/
package chemaxon.examples.strucrep;
import java.io.IOException;
import chemaxon.calculations.clean.Cleaner;
import chemaxon.formats.MolExporter;
import chemaxon.formats.MolImporter;
import chemaxon.struc.Molecule;
import chemaxon.struc.RxnMolecule;
/**
* Example class. Creates a basic RxnMolecule.
*
* @author Janos Kendi
*
*/
public class BuildRxnMolecule {
public static void main(String[] args) throws IOException {
// Create an empty reaction
RxnMolecule mol = new RxnMolecule();
// Create the components
Molecule reactant1 = MolImporter.importMol("CC(=C)C");
Molecule reactant2 = MolImporter.importMol("Cl");
Molecule agent = MolImporter.importMol("CCOCC");
Molecule product = MolImporter.importMol("C(Cl)(C)(C)C");
// Add the components
mol.addComponent(reactant1, RxnMolecule.REACTANTS);
mol.addComponent(reactant2, RxnMolecule.REACTANTS);
mol.addComponent(agent, RxnMolecule.AGENTS);
mol.addComponent(product, RxnMolecule.PRODUCTS);
// Calculate coordinates.
Cleaner.clean(mol, 2, null);
// Change the reaction arrow type.
mol.setReactionArrowType(RxnMolecule.EQUILIBRIUM);
System.out.println(MolExporter.exportToFormat(mol, "mrv:P"));
}
}
Reaction of aromatic nitration
package chemaxon.examples.strucrep
import chemaxon.struc.*;
import chemaxon.formats.MolImporter;
import chemaxon.formats.MolFormatException;
/**
* Example class for structure manipulation.
* Creates a simple reaction.
*
* @author Andras Volford
*
*/
public class AromaticNitration {
public static void main(String[] args) {
// create an empty Molecule
RxnMolecule m = new RxnMolecule();
try{
Molecule reactant = MolImporter.importMol("c1ccccc1");
Molecule agent = MolImporter.importMol("N(O)(=O)=O.S(O)(O)(=O)=O");
Molecule product = MolImporter.importMol("c1ccccc1N(=O)=O");
m.addComponent(reactant, RxnMolecule.REACTANTS);
m.addComponent(agent, RxnMolecule.AGENTS);
m.addComponent(product, RxnMolecule.PRODUCTS);
m.addComponent(MolImporter.importMol("O"), RxnMolecule.PRODUCTS);
System.out.println(m.toFormat("mrv"));
} catch (MolFormatException e) {
System.err.println("Format not recognised.");
}
}
}
Aromatization
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
* This software is the confidential and proprietary information of
* ChemAxon. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with ChemAxon.
*
*/
package chemaxon.examples.strucrep;
import chemaxon.formats.MolFormatException;
import chemaxon.formats.MolImporter;
import chemaxon.struc.MolBond;
import chemaxon.struc.Molecule;
import chemaxon.struc.MoleculeGraph;
/**
* Example class for aromatization.
*
* @author Janos Kendi
*
*/
public class AromatizationExample {
public static void main(String[] args) throws MolFormatException {
// Import a molecule from smiles
Molecule mol = MolImporter.importMol("O=C1NC=CC=C1");
// Call basic aromatization method
mol.aromatize(MoleculeGraph.AROM_BASIC);
System.out.println("Aromatic: " + isAromatic(mol));
// Call general aromatization method
mol.aromatize(MoleculeGraph.AROM_GENERAL);
System.out.println("Aromatic: " + isAromatic(mol));
}
/**
* Check if the given molecule is aromatic or not.
*
* @param m
* @return true if the molecule is aromatic, false otherwise
*/
public static boolean isAromatic(Molecule m) {
boolean aromatic = false;
for (MolBond b : m.getBondArray()) {
if (b.getType() == MolBond.AROMATIC) {
aromatic = true;
break;
}
}
return aromatic;
}
}
Periodic System
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
* This software is the confidential and proprietary information of
* ChemAxon. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with ChemAxon.
*
*/
package chemaxon.examples.strucrep;
import chemaxon.struc.PeriodicSystem;
import static chemaxon.struc.PeriodicSystem.*;
/**
* Example methods of the PeriodicSystem class.
*
* @author Janos Kendi
*
*/
public class PeriodicSystemExample {
public static void main(String[] args) {
System.out.println("Atomic number of C: "
+ PeriodicSystem.findAtomicNumber("C"));
System.out.println("Mass of C: " + PeriodicSystem.getMass(C));
System.out.println("Column of C: " + PeriodicSystem.getColumn(C));
System.out.println("Number of C isotopes: "
+ PeriodicSystem.getIsotopeCount(C));
}
}
Build molecules with Superatom S-group and Repeating unit S-group
/*
* Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
* This software is the confidential and proprietary information of
* ChemAxon. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with ChemAxon.
*
*/
package chemaxon.examples.strucrep;
import java.io.IOException;
import chemaxon.calculations.clean.Cleaner;
import chemaxon.formats.MolExporter;
import chemaxon.formats.MolImporter;
import chemaxon.marvin.util.CleanUtil;
import chemaxon.struc.Molecule;
import chemaxon.struc.Sgroup;
import chemaxon.struc.graphics.MBracket;
import chemaxon.struc.sgroup.RepeatingUnitSgroup;
import chemaxon.struc.sgroup.SuperatomSgroup;
/**
* Example class for creating sgroups.
*
* @author Janos Kendi
*
*/
public class BuildMoleculeWithSgroupExample {
public static void main(String[] args) throws IOException {
// Import the molecule
Molecule mol = MolImporter.importMol("C1=CC=CC=C1C(C)CC");
Cleaner.clean(mol, 2, null);
// Create Superatom S-group.
SuperatomSgroup superSg = new SuperatomSgroup(mol);
for (int i = 0; i < 6; i++) {
mol.setSgroupParent(mol.getAtom(i), superSg, true);
}
superSg.setSubscript("Ph");
//Add attachment point. The attach atom is the fifth of the molecule.
//The crossing bond is also fifth one of the molecule.
superSg.addAttachmentPoint(mol.getAtom(5), 1);
superSg.addCrossingBond(mol.getAtom(5), mol.getBond(5));
//Create Repeating unit S-group
RepeatingUnitSgroup repeatingSg = new RepeatingUnitSgroup(mol, "ht",
Sgroup.ST_SRU);
// Set the RepeatingUnitSgroup atoms.
for (int i = 0; i < 9; i++) {
if (mol.getAtom(i).getBondCount() > 1) {
mol.setSgroupParent(mol.getAtom(i), repeatingSg, true);
}
}
repeatingSg.addStarAtoms();
// Set the parent-child relation.
repeatingSg.addChildSgroup(superSg);
CleanUtil.generateBracketCoords(repeatingSg, MBracket.T_SQUARE);
System.out.println(MolExporter.exportToFormat(mol, "mrv:P"));
}
}
|
Graphic Object handling |
|