use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.
the class NewChainAction method onMouseUp.
public boolean onMouseUp(IMouseEvent evt) {
boolean ok = false;
model.pushUndo();
java.awt.geom.Point2D pt = new Point2D.Double(evt.getX(), evt.getY());
StereoMolecule mol = model.getMolecule();
if (numChainAtoms == 0) {
mol = model.getMoleculeAt(pt, false);
if (mol != null) {
int atom = model.getSelectedAtom();
if (atom != -1) {
addSingleBondAtAtom(mol, atom);
}
}
} else if (numChainAtoms > 0) {
if (sourceAtom == -1) {
sourceAtom = mol.addAtom((float) origin.getX(), (float) origin.getY());
}
if (mChainAtom[0] == -1) {
mChainAtom[0] = mol.addAtom((float) mChainAtomX[0], (float) mChainAtomY[0]);
}
if (mChainAtom[0] != -1) {
mol.addBond(sourceAtom, mChainAtom[0]);
}
if (model.isReaction())
model.needsLayout(true);
}
if (numChainAtoms > 1) {
for (int i = 1; i < numChainAtoms; i++) {
if (mChainAtom[i] == -1) {
mChainAtom[i] = mol.addAtom((float) mChainAtomX[i], (float) mChainAtomY[i]);
}
if (mChainAtom[i] != -1) {
mol.addBond(mChainAtom[i - 1], mChainAtom[i]);
}
}
if (model.isReaction())
model.needsLayout(true);
}
highlightAtom(mol, -1);
ok = true;
dragging = false;
return ok;
}
use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.
the class ChemDrawCDX method getTransform.
private MolGeom getTransform(Reaction rxn) {
double xmin = Double.MAX_VALUE;
double xmax = Double.MIN_VALUE;
double ymin = Double.MAX_VALUE;
double ymax = Double.MIN_VALUE;
double scale = Double.MAX_VALUE;
int cnt = rxn.getMolecules();
if (cnt < 1)
return new MolGeom(0, 0, 1);
for (int mi = 0; mi < cnt; mi++) {
StereoMolecule m = rxn.getMolecule(mi);
m.ensureHelperArrays(Molecule.cHelperCIP);
int na = m.getAllAtoms();
// if more than one atom....
for (int i = 0; i < na; i++) {
double x = m.getAtomX(i);
double y = m.getAtomY(i);
xmin = Math.min(xmin, x);
xmax = Math.max(xmax, x);
ymin = Math.min(ymin, y);
ymax = Math.max(ymax, y);
}
double dx = xmax - xmin;
double dy = xmax - ymin;
debug(String.format("Mofile dx = %f dy = %f", dx, dy));
double xscale = (double) 0x01000000 / dx;
double yscale = (double) 0x01000000 / dy;
debug(String.format("Mofile scale x = %.16f y = %.16f", xscale, yscale));
scale = Math.min(xscale, yscale);
}
return new MolGeom(xmin, ymin, scale);
}
use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.
the class ChemDrawCDX method getChemDrawBuffer.
public byte[] getChemDrawBuffer(Reaction rxn) {
CDXDocument doc = new CDXDocument();
int r = rxn.getReactants();
int p = rxn.getProducts();
int mn = rxn.getMolecules();
doc.add(new CDPShowEnhAtomStereo(true));
doc.add(new CDPShowAtomStereo(true));
doc.add(new CDPShowBondStereo(true));
CDXNode page = new CDXPage();
doc.add(page);
MolGeom g = getTransform(rxn);
int[] rids = new int[r];
for (int i = 0; i < r; i++) {
StereoMolecule m = rxn.getReactant(i);
CDXNode frag = new CDXFragment();
writeMolecule(m, frag, g);
rids[i] = frag.getID();
page.add(frag);
}
int[] pids = new int[p];
for (int i = 0; i < p; i++) {
StereoMolecule m = rxn.getProduct(i);
CDXNode frag = new CDXFragment();
writeMolecule(m, frag, g);
pids[i] = frag.getID();
page.add(frag);
}
CDXReactionStep step = new CDXReactionStep(rids, pids);
page.add(step);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
LittleEndianDataOutputStream l = new LittleEndianDataOutputStream(bos);
write(l, doc);
try {
bos.close();
} catch (IOException ex) {
System.err.println("ChemDrawCDX::getChemDrawBuffer(): Error closing stream : " + ex);
}
return bos.toByteArray();
}
use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.
the class ChemDrawCDX method writeMolecule.
private void writeMolecule(StereoMolecule mol, CDXNode frag, MolGeom g) {
StereoMolecule m = new StereoMolecule(mol);
m.ensureHelperArrays(Molecule.cHelperCIP);
int na = m.getAllAtoms();
int nb = m.getAllBonds();
CDXAtom[] atoms = new CDXAtom[na];
if (false) {
double xmin = m.getAtomX(0);
double xmax = m.getAtomX(0);
double ymin = m.getAtomY(0);
double ymax = m.getAtomY(0);
// if more than one atom....
for (int i = 1; i < na; i++) {
double x = m.getAtomX(i);
double y = m.getAtomY(i);
xmin = Math.min(xmin, x);
xmax = Math.max(xmax, x);
ymin = Math.min(ymin, y);
ymax = Math.max(ymax, y);
}
double dx = xmax - xmin;
double dy = xmax - ymin;
debug(String.format("Mofile dx = %f dy = %f", dx, dy));
double xscale = (double) 0x00800000 / dx;
double yscale = (double) 0x00800000 / dy;
debug(String.format("Mofile scale x = %.16f y = %.16f", xscale, yscale));
debug("Before translate");
for (int i = 0; i < na; i++) {
double x = m.getAtomX(i);
double y = m.getAtomY(i);
debug(String.format("O Atom x = %.16f y = %.16f", x, y));
}
double scale = Math.min(xscale, yscale);
m.translateCoords((float) xmin, (float) ymin);
m.scaleCoords((float) scale);
} else {
// MolGeom g = getTransform(mol);
m.translateCoords((float) -g.xmin, (float) -g.ymin);
m.scaleCoords((float) g.scale);
}
// debug("After translate");
// for(int i = 0;i < na;i++){
// double x = m.getAtomX(i);
// double y = m.getAtomY(i);
// debug(String.format("Atom x = %.16f y = %.16f",x,y));
// }
boolean isMethane = na == 1 && m.getAtomicNo(0) == 6;
for (int i = 0; i < na; i++) {
double x = m.getAtomX(i);
double y = m.getAtomY(i);
debug(String.format("C Atom x = %.0f y = %.0f", x, y));
CDXAtom atom = null;
if (isMethane) {
atom = new CDXMethane(0x00100000 + (int) x, 0x00100000 + (int) y);
} else {
atom = new CDXAtom((short) m.getAtomicNo(i), 0x00100000 + (int) x, 0x00100000 + (int) y);
}
if (m.isAtomStereoCenter(i)) {
int grp = m.getAtomESRGroup(i);
int esr = m.getAtomESRType(i);
if (!m.isAtomConfigurationUnknown(i) && !m.getStereoProblem(i)) {
atom.setAtomESRStereo(esr);
}
debug("Group is " + grp);
if (grp != -1) {
atom.setAtomESRGroup(grp + 1);
}
if (m.getAtomCIPParity(i) != 0) {
atom.setAtomCIP(m.getAtomCIPParity(i), m.getAtomPi(i) == 2, m.isAtomParityPseudo(i));
}
if (m.getAtomMass(i) != 0) {
atom.setAtomMass((short) m.getAtomMass(i));
}
if (m.getAtomCharge(i) != 0) {
atom.setAtomCharge((byte) m.getAtomCharge(i));
}
if (m.getAtomRadical(i) != 0) {
atom.setAtomRadical((byte) m.getAtomRadical(i));
}
}
// CDXAtom at2 = new CDXAtom((short)8, 0x02000000, 0x00AC03BA);
// CDXAtom atom = new CDXAtom((short)7,(int)x,(int)y);
atoms[i] = atom;
frag.add(atom);
}
// For all bonds
for (int i = 0; i < nb; i++) {
int a1 = m.getBondAtom(0, i);
int a2 = m.getBondAtom(1, i);
int o = m.getBondType(i);
CDXBond b = new CDXBond(atoms[a1].getID(), atoms[a2].getID());
b.setBondType(o);
frag.add(b);
}
}
use of com.actelion.research.chem.StereoMolecule in project openchemlib by Actelion.
the class ChemDrawCDX method getTransform.
private MolGeom getTransform(StereoMolecule mol) {
StereoMolecule m = new StereoMolecule(mol);
m.ensureHelperArrays(Molecule.cHelperCIP);
int na = m.getAllAtoms();
double xmin = m.getAtomX(0);
double xmax = m.getAtomX(0);
double ymin = m.getAtomY(0);
double ymax = m.getAtomY(0);
// if more than one atom....
for (int i = 1; i < na; i++) {
double x = m.getAtomX(i);
double y = m.getAtomY(i);
xmin = Math.min(xmin, x);
xmax = Math.max(xmax, x);
ymin = Math.min(ymin, y);
ymax = Math.max(ymax, y);
}
double dx = xmax - xmin;
double dy = xmax - ymin;
debug(String.format("Mofile dx = %f dy = %f", dx, dy));
double xscale = (double) 0x00A00000 / dx;
double yscale = (double) 0x00A00000 / dy;
debug(String.format("Mofile scale x = %.16f y = %.16f", xscale, yscale));
return new MolGeom(xmin, ymin, Math.min(xscale, yscale));
}
Aggregations