def prep_config( config_file: Optional[str] = None, results: Optional[WorkFlowResult] = None, cores: Optional[int] = None, memory: Optional[int] = None, protocol: Optional[str] = None, ) -> WorkFlow: """A helper function to load the config file for the CLI and update common options. Note: If not config file path is given then we load the default workflow. """ if config_file is not None and protocol is not None: raise RuntimeError( "The `protocol` and `config` options are mutually exclusive please only supply one." ) # load the local config if config_file is not None: workflow = WorkFlow.parse_file(config_file) # load config from results elif results is not None: workflow = WorkFlow.from_results(results=results) elif protocol is not None: workflow = get_workflow_protocol(workflow_protocol=protocol) else: # use the basic workflow if no config given, model 0 workflow = get_workflow_protocol(workflow_protocol="0") # update the workflow workflow.local_resources.cores = cores or workflow.local_resources.cores workflow.local_resources.memory = memory or workflow.local_resources.memory return workflow
def test_build_results_optional(acetone): """ Test building a results object with an optional stage. """ model0 = get_workflow_protocol(workflow_protocol="0") result = model0._build_initial_results(molecule=acetone) assert result.results["virtual_sites"].stage_settings is None
def test_to_file(filename, tmpdir): """ Test writing to file. """ model = get_workflow_protocol(workflow_protocol="0") with tmpdir.as_cwd(): model.to_file(filename=filename)
def test_results_round_trip(acetone, workflow_model): """ Test round tripping a workflow to and from results. """ workflow = get_workflow_protocol(workflow_protocol=workflow_model) results = workflow._build_initial_results(molecule=acetone) workflow_2 = WorkFlow.from_results(results=results) assert workflow.json() == workflow_2.json()
def test_optional_stage_skip(skip_stages): """ Test adding the optional stages to the skip list. """ # has no vsite stage model0 = get_workflow_protocol(workflow_protocol="0") skips = model0._get_optional_stage_skip(skip_stages=skip_stages) assert "virtual_sites" in skips
def test_config_prep_file(tmpdir): """ Make sure we can load a config file. """ with tmpdir.as_cwd(): workflow_0 = get_workflow_protocol(workflow_protocol="0") workflow_0.to_file(filename="workflow.json") workflow = prep_config(config_file="workflow.json") assert workflow.json() == workflow_0.json()
def test_build_results(acetone): """ Make sure we can build a results object from the workflow which captures the correct settings. """ # get a model with all stages present model5a = get_workflow_protocol(workflow_protocol="5a") result = model5a._build_initial_results(molecule=acetone) assert result.input_molecule.json() == acetone.json() for result in result.results.values(): assert result.status == "waiting"
def test_validate(tmpdir, run_cli): """ Test validating a workflow via the cli. """ workflow = get_workflow_protocol(workflow_protocol="0") workflow.to_file(filename="workflow.json") output = run_cli.invoke(validate, args=["workflow.json"]) # gaussian is not installed so make sure we have the correct error assert output.exit_code == 1 assert isinstance(output.exception, SpecificationError)
def test_validate_workflow(acetone): """ Make sure workflow validation correctly checks the specification and each stage. """ model0 = get_workflow_protocol(workflow_protocol="0") # change to an rdkit spec which is available always model0.qc_options.program = "rdkit" model0.qc_options.method = "uff" model0.qc_options.basis = None # assuming no psi4 or gaussian run_order = WorkFlow.get_running_order(skip_stages=["charges"]) model0.validate_workflow(workflow=run_order, molecule=acetone)
def create(filename: str, protocol: str) -> None: """Create a new config file using the standard workflow and write to file.""" w = get_workflow_protocol(workflow_protocol=protocol) w.to_file(filename=filename)