Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(self):
"""Does the class initialize correctly?"""
fpath = os.path.join(__datadir__, "data/ADF/basicADF2007.01/dvb_gopt.adfout")
data = cclib.io.ccread(fpath)
xyz = cclib.io.xyzwriter.XYZ(data)
# The object should keep the ccData instance passed to its constructor.
self.assertEqual(xyz.ccdata, data)
def test_init(self):
"""Does the class initialize correctly?"""
fpath = os.path.join(__datadir__, "data/ADF/basicADF2007.01/dvb_gopt.adfout")
data = cclib.io.ccread(fpath)
xyz = cclib.io.xyzwriter.XYZ(data)
# The object should keep the ccData instance passed to its constructor.
self.assertEqual(xyz.ccdata, data)
def test_outputclass(self):
"""Does the function determine output class as expected."""
outputtype = "xyz"
outputdest = "file.xyz"
self.assertEqual(self._determine_output_format(outputtype, outputdest),
cclib.io.xyzwriter.XYZ)
# Must raise a KeyError for unsuported extensions
self.assertRaises(self.UnknownOutputFormatError,
self._determine_output_format, 'ext', outputdest)
self.assertRaises(self.UnknownOutputFormatError,
self._determine_output_format, None, None)
def test_roundtrip_two(self):
"""Does a written XYZ file with two structures match a reference
output?
Perform a roundtrip test, reading an XYZ file into a ccData
instance then writing it out again.
"""
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.
writer = cclib.io.xyzwriter.XYZ(data, allgeom=True)
new_repr = writer.generate_repr()
ref_fpath = os.path.join(__filedir__, "data/uracil_two_ref.xyz")
with open(ref_fpath) as ref:
# Compare the contents of the reference file (left) with
# the string representation generated by the writer
# (right).
assert ref.read() == new_repr
def test_subclass(self):
"""Is the writer a subclass of the abstract file writer?"""
fpath = os.path.join(__datadir__, "data/ADF/basicADF2007.01/dvb_gopt.adfout")
self.assertTrue(os.path.exists(fpath))
data = cclib.io.ccread(fpath)
writer = cclib.io.xyzwriter.XYZ(data)
self.assertTrue(isinstance(writer, cclib.io.filewriter.Writer))
self.assertTrue(issubclass(type(writer), cclib.io.filewriter.Writer))
def test_roundtrip_one(self):
"""Does a written XYZ file with a single structure match a reference
output?
Perform a roundtrip test, reading an XYZ file into a ccData
instance then writing it out again.
"""
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()
ref_fpath = os.path.join(__filedir__, "data/uracil_one_ref.xyz")
with open(ref_fpath) as ref:
# Compare the contents of the reference file (left) with
# the string representation generated by the writer
# (right).
assert ref.read() == new_repr
firstgeom=False, lastgeom=False, allgeom=False,
*args, **kwargs):
"""Initialize the XYZ writer object.
Inputs:
ccdata - An instance of ccData, parse from a logfile.
splitfiles - Boolean to write multiple files if multiple files are requested. [TODO]
firstgeom - Boolean to write the first available geometry from the logfile.
lastgeom - Boolean to write the last available geometry from the logfile.
allgeom - Boolean to write all available geometries from the logfile.
"""
self.required_attrs = ('natom', 'atomcoords', 'atomnos')
# Call the __init__ method of the superclass
super(XYZ, self).__init__(ccdata, *args, **kwargs)
self.do_firstgeom = firstgeom
self.do_lastgeom = lastgeom
self.do_allgeom = allgeom
self.natom = str(self.ccdata.natom)
self.element_list = [self.pt.element[Z] for Z in self.ccdata.atomnos]