uniform bond length in MarvinView

User 870ab5b546

18-01-2010 00:33:52

I have a page with a series of MarvinView applets (not a table).  I want the bond length in all the applets to be set to the same value regardless of the size of the molecule.  I tried


mview_param("scale", "32");
mview_param("winScale", "32");
mview_param("tabScale", "32");

but either they had no effect or they caused an error.  The first command works in MarvinSketch.  How do I set this parameter in MarvinView?

User 870ab5b546

19-01-2010 01:30:39

I figured out a way to do it, although it's not trivial.  It requires a call to the Java API.


    public static int[] getBestAppletSize(String molStruct,
boolean showAtomMapping) {
final int OPT_WIDTH = 250; // preferred # pixels in width
final int MAX_SCALE = 40; // largest scale that looks OK
final int MIN_SCALE = 16; // smallest scale that looks OK
int[] dims = new int[] {OPT_WIDTH, OPT_WIDTH};
if (molStruct == null) {
return dims;
}
final StringBuilder imgParams = new StringBuilder(32);
try {
boolean isLewis = (molStruct.indexOf("Lewis ") > -1);
imgParams.append("jpeg:mono,wireframe,scale");
imgParams.append(MAX_SCALE);
imgParams.append(isLewis ? ",H_off" : ",H_heteroterm");
if (showAtomMapping) imgParams.append(",amap");
Molecule mol = MolImporter.importMol(molStruct);
MolImageSize imgSize = mol.getImageSize(imgParams.toString());
// determine appropriate width
if (imgSize.width < OPT_WIDTH) {
// use width and height at scale 40
dims[0] = imgSize.width;
dims[1] = imgSize.height;
} else {
// scale down
double smallerScale = ((double) (MAX_SCALE * OPT_WIDTH))
/ (double) imgSize.width;
if (smallerScale > ((double) MIN_SCALE)) {
// use optimum width
dims[0] = OPT_WIDTH;
dims[1] = (imgSize.height * OPT_WIDTH) / imgSize.width;
} else {
// use width that gives minimum bond length
dims[0] = (imgSize.width * MIN_SCALE) / MAX_SCALE;
dims[1] = (imgSize.height * MIN_SCALE) / MAX_SCALE;
} // if scale
} // if imgSize.width
} catch (MolFormatException e1) {
System.out.println(SELF + "MolFormatException for " + molStruct);
e1.printStackTrace();
} catch (Exception e2) {
System.out.println(SELF + "got the following exception on "
+ molStruct);
e2.printStackTrace();
}
return dims;
} // getBestAppletSize(String, boolean)


ChemAxon 7c2d26e5cf

21-01-2010 10:03:03

Thanks for sharing your experience.