def test_warn_not_cubic(self): import sys from io import StringIO warn_message = '*************WARNING*************\nThe given lattice vectors\n' \ '[[10. 0. 0. ]\n [ 0. 10.54664 0. ]\n' \ ' [ 0. 0. 10.54664]]\n' \ 'do not constitute a simple basic lattice.\n' \ 'The programm wont work correctly' wrong_parser = Parser('test_data/wrong_data_outcar.21') saved_stdout = sys.stdout try: out = StringIO() sys.stdout = out wrong_parser.find_lattice_vectors() output = out.getvalue().strip() self.assertEqual(output, warn_message, 'Warning message is not correct') finally: sys.stdout = saved_stdout
def test_read_lattice_vecors(self): test_in = 'OUTCAR.21' parser = Parser(test_in) test_lattice = np.array([ [10.546640000, 0.000000000, 0.000000000], [0.000000000, 10.546640000, 0.000000000], [0.000000000, 0.000000000, 10.546640000] ]) self.assertTrue( np.array_equal(parser.find_lattice_vectors(), test_lattice), 'lattice vectors do not match' )
def load_data(u_conf: dict, stepsize=0) -> (int, int, np.array, list): ''' Loads the data from the file specified in u_conf and returns the parameters of the simulation as (N_conf, N_ion, lattice vectors, list of configurations) ''' if stepsize == 0: stepsize = int(input("Stepsize for prediction? (integer): -> ")) # load parser and save nr of ions and lattice vectors parser = Parser(u_conf['file_in']) lattice_vectors = parser.find_lattice_vectors() lat_consts = np.diag(lattice_vectors.dot(lattice_vectors.T)) # check if lattice constant is bigger than 2 rcut if any(np.greater(2 * u_conf["cutoff"], lat_consts)): raise ValueError('Cutoff cannot be bigger than half the lattice constants') # build the configurations from the parser configurations = [ Configuration(position, energy, forces) for (energy, position, forces) in parser .build_configurations(stepsize) ] return (len(configurations), parser.find_ion_nr(), lattice_vectors, configurations)