def test_plot(self): "Make sure object could plot" filename = path + "/OSZICAR" oszicar = OsziCar(filename) plot = oszicar.plot('E0', mode='save') self.assertTrue(isinstance(plot, matplotlib.figure.Figure)) # Remove picture. os.remove("E0_vs_step.png")
def test_attrs(self): "Make sure load() effects" filename = path + "/OSZICAR" oszicar = OsziCar(filename) for var in oszicar.vars: self.assertTrue(hasattr(oszicar, var)) #should raise an exception for an AttributeError self.assertRaises(AttributeError)
def test_esort(self): "Make sure the esort() effects" filename = path + "/OSZICAR" oszicar = OsziCar(filename) srted = oszicar.esort('E0', 2) shouldbe = np.array([(-101.21186, 326), (-101.21116, 324)], dtype=[('var', '<f8'), ('step', '<i4')]) #self.assertTrue((srted == shouldbe).all()) srted = srted.tolist() shouldbe = shouldbe.tolist() self.assertTrue(srted == shouldbe)
def setUp(self): #create an instance of OSZICAR file self.x = OsziCar('./testdata/OSZICAR')
direct_coordinates = data suffix = "-{}.xsd".format(step) else: # the last step data contcar = atomco.ContCar() direct_coordinates = contcar.data suffix = '-y.xsd' # create .xsd file status, output = subprocess.getstatusoutput('ls *.xsd | head -1') if not output.endswith('.xsd'): _logger.info("No .xsd file in current directory.") sys.exit(1) xsd = matstudio.XsdFile(filename=output) xsd.data = direct_coordinates # Get energy and force. oszicar = OsziCar() outcar = OutCar() # Get force and energy for specific step. idx = int(args.step) - 1 if args.step else -1 xsd.force = outcar.total_forces[idx] _logger.info("Total Force --> {}".format(xsd.force)) xsd.energy = oszicar.E0[idx] _logger.info("Total Energy --> {}".format(xsd.energy)) jobname = output.split('.')[0] xsd.tofile(filename=jobname + suffix) _logger.info("{} created.".format(jobname + suffix))