January 31, 2012

Journal abbreviations in Mendeley

If you are using Mendeley for handling citations in your research papers, you might have run into the issue that by default it cannot generate journal abbreviations. Hence you always get the full journal name which is a bit problematic when trying to adhere to citation standards.
However, with the current Mendeley version this functionality actually exists (but is not advertised anywhere and there are some manual configuration to do). I have not come up with this myself, all credit to Robert Knight in the Mendeley support forum. I'm just copying his intstructions here so I can find it again later, since the original post in the support forum was a bit tricky to find among all the decoys.

You need to create a text file specifying the journal abbreviations to use. The original steps to do this were documented in the discussion at http://feedback.mendeley.com/forums/4941-mendeley-feedback/suggestions/83173-journal-abbreviations. The short version is:

1. Locate your Mendeley Desktop user data folder. You can do this by pressing Ctrl+Shift+D in Mendeley (Cmd+Shift+D on Mac) and clicking 'Open Data Directory'

2. Create a folder inside the data folder called "journalAbbreviations"

3. Within this folder create a plain text file called "default.txt"

4. On each line of the default.txt file, add the full journal name, followed by a TAB character, followed by the associated journal abbreviation. Note that the full journal name is case sensitive. See http://pastebin.com/raw.php?i=tVrUas82 for an example.

5. In Mendeley Desktop, when you change to a new style, the default.txt file will be read and the abbrevations will be used if the style specifies form="short" for "containter-title", like the Vancouver style does for Journal Articles.

January 27, 2012

SMARTCyp with ChemDoodle web components

Recently we released version 2.01 of SMARTCyp, which is the first version to use ChemDoodle web components.

We have done this for two major reasons, the first one is speed. Creating HTML output by writing text files with javascript is much faster than generating three png files for each molecule. While the old version output is still available in SMARTCyp, the default HTML output is HTML5 using ChemDoodle web components. Not only is it faster, it looks nicer too.

The second reason is platform compatibility, the new HTML output can also respond to input from touch-screens. A touch input on the structures (when using your mobile phone or your tablet device) will display atom numbers in the same way a mouseover effect does it on a standard computer. To get this working we simply made duplicate functions in the javascript. There are mousover and mouseout functions for displaying and not displaying atom numbers. The same functions also exist as touchstart and touchend functions. If you want the details, just check out the resulting HTML you get when you run a molecule on our web server.

When we did this we also changed the sketcher on our web server start page. It used to be a JchemPaint sketcher applet. Since this is java it simply does not work on all mobile devices (and Ipads). Now we instead use the ChemDoodle sketcher, which loads much faster, and is compatible for all mobile devices as well.

January 10, 2012

Chemdoodle web components tricks #4: showing atom numbers with the altLabel property

Due to the release of version 4.5 of chemdoodle web compontents we have access to the altLabel property for atoms. This property will replace the atom label when set. This seriously simplifies the display of atom numbers in molecules, so the technique shown here supersedes my old post on the same subject (Chemdoodle web components tricks #2: showing atom numbers).

A canvas with atom numbers shown:

The javascript code for a canvas with atom numbers:
 
  var tutorial4_testmol2 = new ChemDoodle.ViewerCanvas('tutorial4_testmol2', 300, 300);
  tutorial4_testmol2.specs.atoms_useJMOLColors = true;
  var caffeineMolFile = 'Molecule Name\n  CHEMDOOD08070920033D 0   0.00000     0.00000     0\n[Insert Comment Here]\n 14 15  0  0  0  0  0  0  0  0  1 V2000\n   -0.3318    2.0000    0.0000   O 0  0  0  1  0  0  0  0  0  0  0  0\n   -0.3318    1.0000    0.0000   C 0  0  0  1  0  0  0  0  0  0  0  0\n   -1.1980    0.5000    0.0000   N 0  0  0  1  0  0  0  0  0  0  0  0\n    0.5342    0.5000    0.0000   C 0  0  0  1  0  0  0  0  0  0  0  0\n   -1.1980   -0.5000    0.0000   C 0  0  0  1  0  0  0  0  0  0  0  0\n   -2.0640    1.0000    0.0000   C 0  0  0  4  0  0  0  0  0  0  0  0\n    1.4804    0.8047    0.0000   N 0  0  0  1  0  0  0  0  0  0  0  0\n    0.5342   -0.5000    0.0000   C 0  0  0  1  0  0  0  0  0  0  0  0\n   -2.0640   -1.0000    0.0000   O 0  0  0  1  0  0  0  0  0  0  0  0\n   -0.3318   -1.0000    0.0000   N 0  0  0  1  0  0  0  0  0  0  0  0\n    2.0640   -0.0000    0.0000   C 0  0  0  2  0  0  0  0  0  0  0  0\n    1.7910    1.7553    0.0000   C 0  0  0  4  0  0  0  0  0  0  0  0\n    1.4804   -0.8047    0.0000   N 0  0  0  1  0  0  0  0  0  0  0  0\n   -0.3318   -2.0000    0.0000   C 0  0  0  4  0  0  0  0  0  0  0  0\n  1  2  2  0  0  0  0\n  3  2  1  0  0  0  0\n  4  2  1  0  0  0  0\n  3  5  1  0  0  0  0\n  3  6  1  0  0  0  0\n  7  4  1  0  0  0  0\n  4  8  2  0  0  0  0\n  9  5  2  0  0  0  0\n 10  5  1  0  0  0  0\n 10  8  1  0  0  0  0\n  7 11  1  0  0  0  0\n  7 12  1  0  0  0  0\n 13  8  1  0  0  0  0\n 13 11  2  0  0  0  0\n 10 14  1  0  0  0  0\nM  END\n> \n07-08-2009\n';
  var caffeine = ChemDoodle.readMOL(caffeineMolFile);
  // get the dimension of the molecule
  var size = caffeine.getDimension();
  // find the scale by taking the minimum of the canvas/size ratios
  var scale = Math.min(tutorial4_testmol2.width/size.x, tutorial4_testmol2.height/size.y);
  // load the molecule first (this function automatically sets scale, so we need to change specs after)
  tutorial4_testmol2.loadMolecule(caffeine);
  // change the specs.scale value to the scale calculated, shrinking it slightly so that text is not cut off
  tutorial4_testmol2.specs.scale = scale*.9;

  //now display atom numbers instead of element letter
  for (var i = 0, ii=caffeine.atoms.length; i<ii; i++) {
     caffeine.atoms[i].altLabel = i+1;
  }
  //repaint the canvas in correct scale with atom numbers
  tutorial4_testmol2.repaint();

January 2, 2012

Using CDK to output a ChemDoodle web component canvas

A very short description of how to get your CDK java code to output a canvas that can be displayed using the ChemDoodle web components java script library.
What ChemDoodle web components needs is actually a molfile with 2D coordinates on one line without line breaks (and explicit \n in place of the line breaks). So that's what we're generating here.
The molecule (variable name "molecule" is assumed to have 2D coordinates, if it only has 3D coordinates it will not look very nice, and without coordinates it will not work at all.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MDLV2000Writer writer = new MDLV2000Writer(baos);

//force 2D coordinates even if 3D exists
Properties customSettings = new Properties();
customSettings.setProperty("ForceWriteAs2DCoordinates", "true");
PropertiesListener listener = new PropertiesListener(customSettings);
writer.addChemObjectIOListener(listener);
//end force 2D coordinates

//write the molecule to the outputstream
try {
   writer.write(molecule);
} catch (CDKException e) {
   e.printStackTrace();
}

//convert the outputstream to a string
String MoleculeString = baos.toString();

//now split MoleculeString into multiple lines to enable explicit printout of \n
String Moleculelines[] = MoleculeString.split("\\r?\\n");

//now we print the javascript variable in the canvas
outfile.print("var myMolFile = '");
for(int i=0; i<Moleculelines.length; i++){
   outfile.print(Moleculelines[i]);
   outfile.print("\\n");
}  
And then you just have to surround this javascript variable with the required settings and canvas definitions as described in my earlier posts about ChemDoodle: Chemdoodle web components tricks #1: scaling molecules, Chemdoodle web components tricks #2: showing atom numbers , Chemdoodle web components tricks #3: Using mouseover functions to do multiple repaints on a canvas