Exemple #1
0
    def set_ase(self, aseatoms):
        """
        Set the contents of the CifData starting from an ASE atoms object

        :param aseatoms: the ASE atoms object
        """
        import tempfile
        cif = cif_from_ase(aseatoms)
        with tempfile.NamedTemporaryFile() as f:
            with HiddenPrints():
                f.write(pycifrw_from_cif(cif, loops=ase_loops).WriteOut())
            f.flush()
            self.set_file(f.name)
Exemple #2
0
    def set_values(self, values):
        """
        Set internal representation to `values`.

        Warning: This also writes a new CIF file.

        :param values: PyCifRW CifFile object

        .. note:: requires PyCifRW module.
        """
        import tempfile
        with tempfile.NamedTemporaryFile() as f:
            with HiddenPrints():
                f.write(values.WriteOut())
            f.flush()
            self.set_file(f.name)

        self._values = values
Exemple #3
0
    def _prepare_cif(self, trajectory_index=None, main_file_name=""):
        """
        Write the given trajectory to a string of format CIF.
        """
        import CifFile
        from aiida.orm.data.cif \
            import ase_loops, cif_from_ase, pycifrw_from_cif
        from aiida.common.utils import HiddenPrints

        cif = ""
        indices = range(self.numsteps)
        if trajectory_index is not None:
            indices = [trajectory_index]
        for idx in indices:
            structure = self.get_step_structure(idx)
            ciffile = pycifrw_from_cif(cif_from_ase(structure.get_ase()),
                                       ase_loops)
            with HiddenPrints():
                cif = cif + ciffile.WriteOut()
        return cif.encode('utf-8'), {}