def export(self, file_name: str) -> None:
        """
        Export the whole factory to file including settings and workflow.

        Args:
            file_name:
                The name of the file the factory should be exported to.
        """
        serialize(serializable=self.dict(), file_name=file_name)
Example #2
0
    def export_schema(self, file_name: str) -> None:
        """
        Export the fitting schema to file.
        """

        if "json" in file_name:
            serialize(self, file_name=file_name)
        else:
            raise RuntimeError(
                "The given file type is not supported please used json.")
Example #3
0
    def export_workflow(self, file_name: str) -> None:
        """
        Export the workflow to yaml or json file.

        Parameters
        ----------
        file_name: str
            The name of the file the workflow should be exported to, the type is determined from the name.
        """

        serialize(serializable=self.dict(), file_name=file_name)
Example #4
0
    def export_settings(self, file_name: str) -> None:
        """
        Export the current model to file this will include the workflow as well along with each components settings.

        Parameters:
            file_name: The name of the file the settings and workflow should be exported to.

        Raises:
            UnsupportedFiletypeError: When the file type requested is not supported.
        """
        serialize(serializable=self, file_name=file_name)
def test_serializer_round_trips(serializer):
    """
    Test serializing data to and from file with no compression.
    """
    # get data in a dict format
    data = deserialize(get_data("settings_with_workflow.json"))
    file_name = "settings_with_workflow" + serializer
    # now export to file and back
    with temp_directory():
        serialize(serializable=data, file_name=file_name, compression=None)
        deserialized_data = deserialize(file_name=file_name)
        assert data == deserialized_data
    def export_workflow(self, file_name: str) -> None:
        """
        Export the workflow components and their settings to file so that they can be loaded later.

        Args:
            file_name: The name of the file the workflow should be exported to.

        Raises:
            UnsupportedFiletypeError: If the file type is not supported.
        """

        # grab only the workflow
        workflow = self.dict(include={"workflow"})
        serialize(serializable=workflow, file_name=file_name)
def test_compression_serialization_round_trip_file_name(
        serialization, compression):
    """
    Test all of the different serialization and compression combinations.
    Here the compression is in the file name.
    """
    # get data in a dict format
    data = deserialize(get_data("settings_with_workflow.json"))
    file_name = "".join(
        ["settings_with_workflow", ".", serialization, ".", compression])
    # now export the file and read back
    with temp_directory():
        serialize(serializable=data, file_name=file_name, compression=None)
        deserialized_data = deserialize(file_name=file_name)
        assert data == deserialized_data
Example #8
0
 def make_scan_metadata(self, task: TorsionTask) -> None:
     """
     Create the metadata.json needed for the constrained optimizations.
     """
     # move to the directory which has already been made
     json_data = {
         "dihedrals":
         task.dihedrals,
         "grid_spacing":
         self.grid_spacings,
         "dihedral_ranges":
         None,
         "energy_decrease_thresh":
         None,
         "energy_upper_limit":
         self.energy_upper_limit,
         "attributes":
         task.attributes.dict(),
         "torsion_grid_ids":
         [data.extras["dihedral_angle"] for data in task.reference_data()],
     }
     # now write to file
     serialize(json_data, os.path.join(task.name, "metadata.json"))