Kekule.js icon indicating copy to clipboard operation
Kekule.js copied to clipboard

Loading XYZ coordinate file

Open schneiderfelipe opened this issue 3 years ago • 6 comments

Is there a way to load a file (or the contents of it) in XYZ format?

schneiderfelipe avatar Oct 15 '20 20:10 schneiderfelipe

Yes, you can load the extra OpenBabel module to enable XYZ format file:

Kekule.OpenBabel.enable(function(err){
  if (!err)
  {
    var molecule = Kekule.IO.loadFormatData(xyzString, 'xyz');
  }
});

partridgejiang avatar Oct 17 '20 04:10 partridgejiang

Thanks, that is pretty much what I was looking for! Is there a way to mix this solution with the HTML-embedded way of defining coordinates? Something like using

<script id="molecule" type="chemical/x-xyz">
2

H    0.000    0.000    0.000
H    0.000    0.000    0.741
</script>

schneiderfelipe avatar Oct 17 '20 15:10 schneiderfelipe

Yes, as the following code shows:

Kekule.OpenBabel.enable(function(err){
  if (!err)
  {
    var molecule = Kekule.IO.loadResourceData('#(molecule)', function(chemObj, success){
      if (success)
        viewer.setChemObj(chemObj);
    });
  }
});

partridgejiang avatar Oct 18 '20 12:10 partridgejiang

@partridgejiang Excellent, thanks!

schneiderfelipe avatar Oct 21 '20 22:10 schneiderfelipe

I am attempting to load xyz data using the method described above (i.e., Kekule.IO.loadFormatData(xyzString, 'xyz')) but I am getting the following error: Problems reading an EXYZ file: Expecting unitcell information because of keyword %PBC but nothing more found Is there a way to set the load function to read xyz data instead of exyz with the %PBC keyword?

My xyz data does not have the %PBC keyword: 62 H30 C26 S2 N4 C 2.738229 0.177781 0.728681 C 1.487649 -0.298650 0.967230 S 0.508526 0.493056 2.163367 C 1.057267 -1.423754 0.325328 C -1.479551 -0.691799 0.763345 C -1.048276 0.435924 1.400311 C 3.577261 -0.491704 -0.112551 C 1.879127 -2.062525 -0.554315 C -2.735044 -0.736111 0.244589 C -1.874472 1.514276 1.508051 C -3.137776 1.457690 1.020028 C -3.574841 0.328501 0.390627 H -3.053407 -1.607759 -0.273985 H -1.529978 2.393077 1.995725 H -3.785983 2.290286 1.144269 C 3.141342 -1.612995 -0.757179 H 3.065998 1.053276 1.234709 H 1.529958 -2.923710 -1.069252 H 3.777274 -2.123940 -1.437882 S -0.492660 -2.117575 0.676966 C -4.912603 0.255483 -0.108776 C -5.990292 0.871376 -0.607204 C -5.997436 -0.478111 -0.381641 N -6.573569 1.938692 -1.000699 N -6.593417 -1.608860 -0.402035 C -5.858084 3.167101 -1.090242 H -6.247437 3.876502 -0.388881 H -4.822594 2.999927 -0.892344 H -5.954494 3.566196 -2.078697 C -7.936670 1.959411 -1.412438 H -8.413336 2.818859 -0.990525 H -8.012196 2.009862 -2.479857 H -8.443726 1.091481 -1.055995 C -5.991417 -2.757986 0.187216 H -5.799041 -3.500438 -0.559901 H -5.076533 -2.485104 0.664406 H -6.648565 -3.168686 0.925594 C -7.906052 -1.772007 -0.929825 H -7.942260 -2.682701 -1.489148 H -8.632132 -1.819550 -0.143427 H -8.141392 -0.968705 -1.591001 C 4.912048 -0.021257 -0.315050 C 6.194369 -0.296924 -0.579671 C 5.786271 0.989829 -0.357748 N 7.113983 -1.145693 -0.839209 N 6.041913 2.239055 -0.261064 C 6.847203 -2.544665 -0.790530 H 7.529968 -3.016056 -0.114350 H 5.853664 -2.713677 -0.439179 H 6.963438 -2.978907 -1.762336 C 8.456362 -0.758565 -1.115721 H 9.082113 -0.908150 -0.259061 H 8.827722 -1.353265 -1.923180 H 8.492107 0.264559 -1.415259 C 4.990060 3.185628 -0.101382 H 5.055644 3.927014 -0.870643 H 4.044993 2.696201 -0.183306 H 5.063480 3.666302 0.852762 C 7.364001 2.759444 -0.357010 H 7.529466 3.208083 -1.315686 H 7.500188 3.501661 0.400895 H 8.078822 1.984985 -0.193485

rduke199 avatar Aug 04 '21 17:08 rduke199

Hi @rduke199, thanks for the feedback. The bug causing save/load xyz format data with exyz reader/writer has been fixed now. Please check the latest dist files, :).

partridgejiang avatar Aug 05 '21 08:08 partridgejiang