Source code for schrodinger.application.steps.test
"""
Utility code for testing of steps
"""
from schrodinger import structure
from schrodinger import stepper
from . import converters
class _FromSmilesChain(stepper.Chain):
    """
    A chain that acts like `step`, but takes SMILES as input.
    """
    def __init__(self, step, **kwargs):
        self.step = step
        super().__init__(**kwargs)
    def buildChain(self):
        self.addStep(converters.SmilesToMolConverter())
        if self.step.Input == structure.Structure:
            self.addStep(converters.MolToStructureConverter())
        self.addStep(self.step)
class _ToSmilesChain(stepper.Chain):
    """
    A chain that acts like `step`, but returns the outputs as canonical SMILES.
    """
    def __init__(self, step, **kwargs):
        self.step = step
        super().__init__(**kwargs)
    def buildChain(self):
        if self.step.Output == structure.Structure:
            self.addStep(converters.StructureToMolConverter())
        self.addStep(converters.MolToSmilesConverter())
[docs]def getOutputs(step, inputs):
    """
    Return all the outputs for the step using the inputs asserting that all
    the step outputs are instances of the proper type.
    :param step: the step to get the outputs for
    :type step: schrodinger.stepper.stepper._BaseStep
    :param inputs: the inputs to use for the step
    :type inputs: list
    """
    step.setInputs(inputs)
    outputs = step.getOutputs()
    assert all(isinstance(obj, step.Output) for obj in outputs)
    return outputs 
[docs]def getOutputsFromSmiles(step, inputs):
    """
    Return all the outputs for the step using the SMILES inputs asserting
    that all the step outputs are instances of the proper type.
    :param step: the step to get the outputs for
    :type step: schrodinger.stepper.stepper._BaseStep
    :param inputs: the SMILES inputs to use for the step
    :type inputs: list
    """
    chain = _FromSmilesChain(step)
    chain.setInputs(inputs)
    outputs = chain.getOutputs()
    assert all(isinstance(obj, step.Output) for obj in outputs)
    return outputs 
[docs]def getSmilesWrappedOutputs(step, inputs):
    """
    Return all canonical SMILES outputs for the step using the SMILES inputs
    asserting that all the step outputs are instances of the proper type.
    :param step: the step to get the outputs for
    :type step: schrodinger.stepper.stepper._BaseStep
    :param inputs: the SMILES inputs to use for the step
    :type inputs: list
    """
    raw_outputs = getOutputsFromSmiles(step, inputs)
    chain = _ToSmilesChain(step)
    chain.setInputs(raw_outputs)
    return chain.getOutputs() 
[docs]def checkValidateSettings(step, msgs=None):
    """
    Asserts that every issue message from the step's validateSettings occurs
    in the msgs in the same order.
    Note no distinction is made between warning or errors.
    :param step: the step whose validateSettings method is to be used
    :type step: stepper._BaseStep
    :param msgs: the list of messages expected
    :type msgs: List[str] or NoneType
    """
    msgs = msgs or []
    validation_messages = [issue.msg for issue in step.validateSettings()]
    assert validation_messages == msgs, f"{msgs=}\n{validation_messages=}" 
[docs]class StepContract:
[docs]    def test_getLicenseRequirements(self):
        raise NotImplementedError() 
[docs]    def test_validateSettings(self):
        raise NotImplementedError() 
[docs]    def test_getOutputs(self):
        raise NotImplementedError()