Repository: cclib/cclib

Issue:
missing `comment` key in parsed `ORCA` `ccData`
I just realized that the parsed object data from `ORCA` (`version 4.2.1`) is missing `comments` key which will result in throwing `KeyError` in the case of writing xyz file. 
https://github.com/cclib/cclib/blob/87abf82c6a06836a2e5fb95a64cdf376c5ef8d4f/cclib/io/xyzwriter.py#L84
Currently, my not-clean work around to continue my work is using `setattribute` method to artificially add it to `metadata` dictionary but I thought to open this issue to report the case and keeping it here until implementing better solution and possibly opening a PR. 
I will be happy to hear opinions on this matter for solving the issue. 

Discussion:

Patch:
diff --git a/cclib/io/xyzwriter.py b/cclib/io/xyzwriter.py
index 5a074cec..da14daa6 100644
--- a/cclib/io/xyzwriter.py
+++ b/cclib/io/xyzwriter.py
@@ -81,7 +81,7 @@ class XYZ(filewriter.Writer):
         """Create an XYZ file of the geometry at the given index."""
 
         atomcoords = self.ccdata.atomcoords[index]
-        existing_comment = "" if not self.ccdata.metadata["comments"] \
+        existing_comment = "" if "comments" not in self.ccdata.metadata \
             else self.ccdata.metadata["comments"][index]
 
         # Create a comment derived from the filename and the index.


Test patch:
diff --git a/test/io/testxyzwriter.py b/test/io/testxyzwriter.py
index 1323c336..372024a8 100644
--- a/test/io/testxyzwriter.py
+++ b/test/io/testxyzwriter.py
@@ -11,7 +11,9 @@ import os
 import unittest
 
 import cclib
+from cclib.parser import QChem
 
+from ..test_data import getdatafile
 
 __filedir__ = os.path.dirname(__file__)
 __filepath__ = os.path.realpath(__filedir__)
@@ -39,7 +41,6 @@ class XYZWriterTest(unittest.TestCase):
         orig_fpath = os.path.join(__datadir__, "test/bridge/uracil.xyz")
         reader = cclib.io.xyzreader.XYZ(orig_fpath)
         data = reader.parse()
-        orig_repr = reader.filecontents
 
         writer = cclib.io.xyzwriter.XYZ(data)
         new_repr = writer.generate_repr()
@@ -61,7 +62,6 @@ class XYZWriterTest(unittest.TestCase):
         orig_fpath = os.path.join(__filedir__, "data/uracil_two.xyz")
         reader = cclib.io.xyzreader.XYZ(orig_fpath)
         data = reader.parse()
-        orig_repr = reader.filecontents
 
         # If not `allgeom`, only the last structure present in a
         # `ccData` will be written out.
@@ -75,6 +75,14 @@ class XYZWriterTest(unittest.TestCase):
             # (right).
             assert ref.read() == new_repr
 
+    def test_quantum_output_repr(self):
+        """Can the XYZ representation be generated from a parsed quantum chemical
+        output?
+        """
+        data, _ = getdatafile(QChem, "basicQChem5.1", ["dvb_sp.out"])
+        writer = cclib.io.xyzwriter.XYZ(data)
+        _ = writer.generate_repr()
+
 
 if __name__ == "__main__":
     unittest.main()