class TestVerdiDataArray(AiidaTestCase): """Testing verdi data array.""" @classmethod def setUpClass(cls): # pylint: disable=arguments-differ super().setUpClass() def setUp(self): self.arr = ArrayData() self.arr.set_array('test_array', np.array([0, 1, 3])) self.arr.store() self.cli_runner = CliRunner() def test_arrayshowhelp(self): output = sp.check_output(['verdi', 'data', 'array', 'show', '--help']) self.assertIn(b'Usage:', output, 'Sub-command verdi data array show --help failed.') def test_arrayshow(self): options = [str(self.arr.id)] res = self.cli_runner.invoke(cmd_array.array_show, options, catch_exceptions=False) self.assertEqual(res.exit_code, 0, 'The command did not finish correctly')
def set_outputs(self): self.report('Setting Outputs') elastic_outputs = ArrayData() #An ugly ugly function to make the symmetry_operations_dict storable def make_symmopdict_aiidafriendly(symmopdict): aiida_symmopdict = dict((str(k).replace('.',','), [x.as_dict() for x in v]) for k, v in symmopdict.items()) return aiida_symmopdict equilibrium_structure = self.ctx.equilibrium_structure.get_pymatgen_structure() symmetry_operations_dict = symmetry_reduce(self.ctx.deformations, equilibrium_structure) symmetry_mapping = make_symmopdict_aiidafriendly(symmetry_operations_dict) symmetry_mapping = Dict(dict=symmetry_mapping) elastic_outputs.set_array('strains', np.array(self.ctx.strains)) elastic_outputs.set_array('stresses', np.array(self.ctx.stresses)) elastic_outputs.set_array('elastic_tensor', np.array(self.ctx.elastic_tensor)) elastic_outputs.set_array("symm_eql_strains", np.array(self.ctx.symm_eql_strains)) elastic_outputs.set_array("symm_eql_stresses", np.array(self.ctx.symm_eql_stresses)) elastic_outputs.store() symmetry_mapping.store() self.out('equilibrium_structure', self.ctx.equilibrium_structure) self.out('elastic_outputs', elastic_outputs) self.out('symmetry_mapping', symmetry_mapping)
def test_valid_node(): """Test that the correct exceptions are thrown for incompatible nodes.""" from aiida.orm import ArrayData, BandsData # Invalid node type node = ArrayData().store() with pytest.raises(ValueError): get_highest_occupied_band(node) # The `occupations` array is missing node = BandsData() node.set_array('not_occupations', numpy.array([])) node.store() with pytest.raises(ValueError): get_highest_occupied_band(node) # The `occupations` array has incorrect shape node = BandsData() node.set_array('occupations', numpy.array([1., 1.])) node.store() with pytest.raises(ValueError): get_highest_occupied_band(node)