partridgejiang / Kekule.js

A Javascript cheminformatics toolkit.
http://partridgejiang.github.io/Kekule.js
MIT License
250 stars 61 forks source link

Bulk setChemObj in composer #84

Closed robertf224 closed 5 years ago

robertf224 commented 5 years ago

I can't figure out how to add multiple molecules. Using setChemObj as described here in sequence doesn't work because each call overrides the previous. Is there some way I can add multiple molecules using the current APIs?

partridgejiang commented 5 years ago

The root object in an composer is actually an instance of Kekule.ChemDocument (when calling composer.setChemObj(molecule), the molecule is actually inserted into this document), so the following code may be used to add multiple molecules to composer:

var molecules = [mol1, mol2, mol3];
var chemDoc = composer.getChemObj();
molecules.forEach(function(mol){
  chemDoc.appendChild(mol);
});
robertf224 commented 5 years ago

awesome thanks!