def convert_phonopy_atoms_to_structure(phonopy_atoms_structure): """ Converts phonopy's representation of a structure to an instance of Structure. """ temporary_write_path = Path.get_temporary_path() Path.validate_does_not_exist(temporary_write_path) Path.validate_writeable(temporary_write_path) write_vasp(temporary_write_path, phonopy_atoms_structure) species_list = convert_phonopy_symbols_to_unique_species_list( phonopy_atoms_structure.symbols) structure_poscar_file = File(temporary_write_path) structure_poscar_file.insert( 5, " ".join(species_list)) #phonopy uses bad poscar format structure_poscar_file.write_to_path() final_structure = Structure(temporary_write_path) Path.remove(temporary_write_path) Structure.validate(final_structure) return final_structure
def test_overrides(self): file = File() self.assertFalse(file) file[2] = ' inserted line ' self.assertEqual(file.lines, ['', '', ' inserted line ']) file[1] = 'add this line\n and this one where index 1 was' self.assertEqual(file.lines, [ '', 'add this line', ' and this one where index 1 was', ' inserted line ' ]) file[1] = 'replaced add this line' self.assertEqual(file.lines, [ '', 'replaced add this line', ' and this one where index 1 was', ' inserted line ' ]) self.assertEqual( file.lines[1:3], ['replaced add this line', ' and this one where index 1 was']) del file[1] del file[0:2] self.assertEqual(file.lines, [' inserted line ']) self.assertFalse("home is where the heart is" in file) self.assertTrue("line" in file) file += "new line added" self.assertEqual(file.lines, [' inserted line ', 'new line added']) file.insert(0, 'inserted at beginning') file.insert(2, 'right before new line added line') self.assertEqual(file.lines, [ 'inserted at beginning', ' inserted line ', 'right before new line added line', 'new line added' ]) self.assertTrue(file) self.assertEqual(len(file), 4) l = [ 'inserted at beginning', ' inserted line ', 'right before new line added line', 'new line added' ] for x, item in enumerate(file): self.assertEqual(item, l[x])