Example #1
0
class OsziCarTest(unittest.TestCase):

    def setUp(self):
        #create an instance of OSZICAR file
        self.x = OsziCar('./testdata/OSZICAR')

    def test_attrs(self):
        "Make sure load() effects"
        for var in self.x.vars:
            self.assertTrue(hasattr(self.x, var))

        #should raise an exception for an AttributeError
        self.assertRaises(AttributeError)

    def test_esort(self):
        "Make sure the esort() effects"
        srted = self.x.esort('E0', 2)
        shouldbe = np.array([(-101.21186, 326), (-101.21116, 324)],
                            dtype=[('var', '<f8'), ('step', '<i4')])
        self.assertTrue((srted == shouldbe).all())

    def test_plot(self):
        "Make sure object could plot"
        plot = self.x.plot('E0', mode='save')
        self.assertTrue(isinstance(plot, matplotlib.figure.Figure))
Example #2
0
class TestOsziCar(unittest.TestCase):

    def setUp(self):
        #create an instance of OSZICAR file
        self.x = OsziCar('../testdata/OSZICAR')

    def test_attrs(self):
        "Make sure load() effects"
        for var in self.x.vars:
            self.assertTrue(hasattr(self.x, var))

        #should raise an exception for an AttributeError
        self.assertRaises(AttributeError)

    def test_esort(self):
        "Make sure the esort() effects"
        srted = self.x.esort('E0', 2)
        shouldbe = np.array([(-101.21186, 326), (-101.21116, 324)],
                            dtype=[('var', '<f8'), ('step', '<i4')])
        self.assertTrue((srted == shouldbe).all())

    def test_plot(self):
        "Make sure object could plot"
        plot = self.x.plot('E0', mode='save')
        self.assertTrue(isinstance(plot, matplotlib.figure.Figure))
Example #3
0
 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")
Example #4
0
 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")
Example #5
0
 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)
Example #6
0
 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)
Example #7
0
    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)
Example #8
0
 def setUp(self):
     #create an instance of OSZICAR file
     self.x = OsziCar('../testdata/OSZICAR')
Example #9
0
 def setUp(self):
     #create an instance of OSZICAR file
     self.x = OsziCar('./testdata/OSZICAR')
Example #10
0
        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))