Exemplo n.º 1
0
    def __init__(self, notebook_path=None, custom_labware_directory=None):
        self.notebook_path = notebook_path
        self.custom_labware_directory = custom_labware_directory
        if self.notebook_path == None or self.custom_labware_directory == None:
            self.notebook_path, self.custom_labware_directory = SelectOT2_Params(
                tkinter.Tk()).results()

        if self.notebook_path == None:
            print("\nProtocol file is required for protocol simulation...\n")
        else:
            print("\nSelected Protocol:", self.notebook_path)
            # check notebook file type
            if os.path.splitext(self.notebook_path)[1] == ".ipynb":
                self.script_path = os.path.splitext(
                    self.notebook_path)[0] + '.py'
                self.auto_conversion()
            elif os.path.splitext(self.notebook_path)[1] == ".py":
                self.script_path = self.notebook_path
            else:
                print(
                    "\nProtocol File Type not Recognised! Please select '.py' or '.ipynb' files...\n"
                )
            if self.custom_labware_directory == None:
                print(
                    "\nCustom labware functions not used for protocol simulation...\n"
                )
                with open(self.script_path, 'r') as file:
                    self.run_log = simulate(protocol_file=file)
            else:
                print("\nSelected Labware definitions folder:",
                      self.custom_labware_directory, "\n")
                with open(self.script_path, 'r') as file:
                    self.run_log = simulate(
                        protocol_file=file,
                        custom_labware_paths=[self.custom_labware_directory])
Exemplo n.º 2
0
def main():
    '''main method.'''
    filename = os.path.realpath(__file__)

    with open(filename) as protocol_file:
        runlog, _ = simulate.simulate(protocol_file, filename)
        print(simulate.format_runlog(runlog))
Exemplo n.º 3
0
def test_simulate_function_bundle_apiv2(get_bundle_fixture):
    bundle = get_bundle_fixture('simple_bundle')
    runlog, bundle = simulate.simulate(
        bundle['filelike'], 'simple_bundle.zip')
    assert bundle is None
    assert [item['payload']['text'] for item in runlog] == [
        'Transferring 1.0 from A1 of FAKE example labware on 1 to A4 of FAKE example labware on 1',  # noqa(E501)
        'Picking up tip from A1 of Opentrons 96 Tip Rack 10 µL on 3',
        'Aspirating 1.0 uL from A1 of FAKE example labware on 1 at 5.0 uL/sec',
        "Dispensing 1.0 uL into A4 of FAKE example labware on 1 at" \
        " 10.0 uL/sec",
        'Dropping tip into A1 of Opentrons Fixed Trash on 12',
        'Transferring 2.0 from A1 of FAKE example labware on 1 to A4 of FAKE example labware on 1',  # noqa(E501)
        'Picking up tip from B1 of Opentrons 96 Tip Rack 10 µL on 3',
        'Aspirating 2.0 uL from A1 of FAKE example labware on 1 at 5.0 uL/sec',
        "Dispensing 2.0 uL into A4 of FAKE example labware on 1 at" \
        " 10.0 uL/sec",
        'Dropping tip into A1 of Opentrons Fixed Trash on 12',
        'Transferring 3.0 from A1 of FAKE example labware on 1 to A4 of FAKE example labware on 1',  # noqa(E501)
        'Picking up tip from C1 of Opentrons 96 Tip Rack 10 µL on 3',
        'Aspirating 3.0 uL from A1 of FAKE example labware on 1 at 5.0 uL/sec',
        "Dispensing 3.0 uL into A4 of FAKE example labware on 1 at" \
        " 10.0 uL/sec",
        'Dropping tip into A1 of Opentrons Fixed Trash on 12'
        ]
Exemplo n.º 4
0
def test_simulate_function_apiv2(ensure_api2, protocol, protocol_file):
    runlog, bundle = simulate.simulate(protocol.filelike, 'testosaur_v2.py')
    assert isinstance(bundle, protocols.types.BundleContents)
    assert [item['payload']['text'] for item in runlog] == [
        'Picking up tip A1 of Opentrons 96 Tip Rack 300 µL on 1',
        'Aspirating 10 uL from A1 of Corning 96 Well Plate 360 µL Flat on 2 at 1.0 speed',  # noqa(E501),
        'Dispensing 10 uL into B1 of Corning 96 Well Plate 360 µL Flat on 2',
        'Dropping tip H12 of Opentrons 96 Tip Rack 300 µL on 1'
    ]
Exemplo n.º 5
0
def test_simulate_function_apiv2(protocol, protocol_file, monkeypatch):
    monkeypatch.setenv('OT_API_FF_allowBundleCreation', '1')
    runlog, bundle = simulate.simulate(protocol.filelike, 'testosaur_v2.py')
    assert isinstance(bundle, protocols.types.BundleContents)
    assert [item['payload']['text'] for item in runlog] == [
        'Picking up tip from A1 of Opentrons 96 Tip Rack 300 µL on 1',
        'Aspirating 10.0 uL from A1 of Corning 96 Well Plate 360 µL Flat on 2 at 150.0 uL/sec',  # noqa(E501),
        'Dispensing 10.0 uL into B1 of Corning 96 Well Plate 360 µL Flat on 2 at 300.0 uL/sec',  # noqa(E501),
        'Dropping tip into H12 of Opentrons 96 Tip Rack 300 µL on 1'
    ]
Exemplo n.º 6
0
def test_simulate_function_apiv1(ensure_api1, protocol, protocol_file):
    runlog, bundle = simulate.simulate(protocol.filelike, 'testosaur.py')
    assert bundle is None
    assert [item['payload']['text'] for item in runlog] == [
        'Picking up tip well A1 in "5"',
        'Aspirating 10 uL from well A1 in "8" at 1.0 speed',
        'Dispensing 10 uL into well H12 in "8"',
        'Aspirating 10 uL from well A1 in "11" at 1.0 speed',
        'Dispensing 10 uL into well H12 in "11"',
        'Dropping tip well A1 in "12"'
    ]
Exemplo n.º 7
0
def test_simulate_function_json_apiv2(ensure_api2, get_json_protocol_fixture):
    jp = get_json_protocol_fixture('3', 'simple', False)
    filelike = io.StringIO(jp)
    runlog, bundle = simulate.simulate(filelike, 'simple.json')
    assert bundle is None
    assert [item['payload']['text'] for item in runlog] == [
        'Picking up tip B1 of Opentrons 96 Tip Rack 10 µL on 1',
        'Aspirating 5 uL from A1 of Source Plate on 2 at 1.0 speed',
        'Delaying for 0m 42s', 'Dispensing 4.5 uL into B1 of Dest Plate on 3',
        'Touching tip', 'Blowing out at B1 of Dest Plate on 3',
        'Dropping tip A1 of Trash on 12'
    ]
Exemplo n.º 8
0
def test_simulate_extra_labware(protocol, protocol_file, monkeypatch):
    fixturedir = HERE / '..' / '..' / '..' /\
        'shared-data' / 'labware' / 'fixtures' / '2'
    # make sure we can load labware explicitly
    # make sure we don't have an exception from not finding the labware
    runlog, _ = simulate.simulate(protocol.filelike, 'custom_labware.py',
                                  custom_labware_paths=[str(fixturedir)])
    assert len(runlog) == 4

    protocol.filelike.seek(0)
    # make sure we don't get autoload behavior when not on a robot
    with pytest.raises(ExceptionInProtocolError,
                       match='.*FileNotFoundError.*'):
        simulate.simulate(protocol.filelike, 'custom_labware.py')
    no_lw = simulate.get_protocol_api('2.0')
    assert not no_lw._extra_labware
    protocol.filelike.seek(0)
    monkeypatch.setattr(simulate, 'IS_ROBOT', True)
    monkeypatch.setattr(simulate, 'JUPYTER_NOTEBOOK_LABWARE_DIR',
                        fixturedir)
    # make sure we don't have an exception from not finding the labware
    runlog, _ = simulate.simulate(protocol.filelike, 'custom_labware.py')
    assert len(runlog) == 4

    # make sure the extra labware loaded by default is right
    ctx = simulate.get_protocol_api('2.0')
    assert len(ctx._extra_labware.keys()) == len(os.listdir(fixturedir))

    assert ctx.load_labware('fixture_12_trough', 1, namespace='fixture')

    # if there is no labware dir, make sure everything still works
    monkeypatch.setattr(simulate, 'JUPYTER_NOTEBOOK_LABWARE_DIR',
                        HERE / 'nosuchdirectory')
    ctx = simulate.get_protocol_api('2.0')
    with pytest.raises(FileNotFoundError):
        ctx.load_labware("fixture_12_trough", 1, namespace='fixture')
Exemplo n.º 9
0
def main():

    parser = argparse.ArgumentParser(
        description=
        "Run a robot's simulation, output well mapping in csv-friendly format")
    parser.add_argument('protocol', type=str)
    parser.add_argument('-o',
                        '--output',
                        type=argparse.FileType('w'),
                        default=sys.stdout)

    args = parser.parse_args()
    protocol_fname = args.protocol
    fidout = args.output

    with open(protocol_fname, 'r') as fid:
        robot_log = simulate.simulate(fid)

    # pprint(robot_log)
    write_header(fidout)
    # loop on command log
    for command in robot_log:
        # extract info from the summary level, so discard all commands not at level 0
        if not is_summary_command(command):
            continue

        # discard commands not involving moving liquid: need source and destination
        if not is_moving_liquid_command(command):
            continue

        case = which_transfer_case(command)
        # 4 cases now atm:
        # - we are dispensing water from the trough
        # - it's a proper one-to-many command,
        # - it's a many-to-many command, (using a well_series object)
        # - it's a one-to-one command, (if using a single tip pipette e.g.)
        if case == 'trough-to-many':
            # ignore trough to many
            pass
        elif case == 'one-to-many':
            process_one2many(command, fidout)
        elif case == 'many-to-many':
            process_many2many(command, fidout)
        elif case == 'one-to-one':
            process_one2one(command, fidout)
        else:
            pass
Exemplo n.º 10
0
    def simulate_program(self):
        """
        This will run an Opentrons simulation on the program.
        """

        # If we have a critical error then don't do anything else.
        if self.critical_error:
            return

        # Select program file if not located where we think it is.
        if not os.path.isfile(self.path_to_program):
            self.path_to_program, _ = \
                QtWidgets.QFileDialog.getOpenFileName(self, self.tr("Select Program File"),
                                                      self.tr("C:{0}Users{0}{1}{0}Documents{0}"
                                                              .format(os.sep, os.getlogin())))

        self.info_report('If you do not get a "Success" notice then the simulation failed.\nSee the terminal window '
                         'for the reason')

        protocol_file = open(self.path_to_program)
        labware_location = "{}{}custom_labware".format(os.path.dirname(self.path_to_program), os.sep)
        run_log, __bundle__ = simulate(protocol_file, custom_labware_paths=[labware_location], propagate_logs=False)

        # Write the simulation steps to a file
        simulation_date = datetime.datetime.today().strftime("%a %b %d %H:%M %Y")
        outfile = open("C:{0}Users{0}{1}{0}Documents{0}{2}_Simulation.txt"
                       .format(os.sep, os.getlogin(), self.selected_program), 'w', encoding="UTF-16")
        step_number = 1
        t = format_runlog(run_log).split("\n")
        outstring = "Opentrons OT-2 Steps.\nDate:  {}\nProgram File: {}\nTSV File:  {}\n\nStep\tCommand\n"\
                    .format(simulation_date, self.selected_program, self.path_to_tsv)

        for line in t:
            outstring += "{}\t{}\n".format(step_number, line)
            step_number += 1
        outfile.write(outstring)
        outfile.close()

        # Write the simulation steps to the GUI
        self.run_simulation_output.insertPlainText(format_runlog(run_log))

        protocol_file.close()
Exemplo n.º 11
0
        dispensing_loop(1, right_pipette, reagent_labware[source_well].bottom(water_tip_height),
                        reagent_labware[destination_well], right_dispensed_vol, NewTip=False, MixReaction=False)

        water_aspirated += right_dispensed_vol
        water_tip_height = res_tip_height(initial_water_volume-water_aspirated, water_res_well_dia, cone_vol)

        count += 1

    left_pipette.drop_tip()
    right_pipette.drop_tip()


if __name__ == "__main__":
    protocol_file = open('Dispensing_Test.py')
    labware_path = "{}{}custom_labware".format(os.getcwd(), os.sep)
    run_log, __bundle__ = simulate(protocol_file, custom_labware_paths=[labware_path])
    run_date = datetime.datetime.today().strftime("%a %b %d %H:%M %Y")
    i = 1
    t = format_runlog(run_log).split("\n")

    outstring = "Opentrons OT-2 Steps for {}.\nDate:  {}\nProgram File: Dispensing_Test.py\n\nStep\tCommand\n" \
        .format(metadata['protocolName'], run_date)

    for l in t:
        outstring += "{}\t{}\n".format(i, l)
        i += 1
    if platform.system() == "Windows":
        outfile = open("C:{0}Users{0}{1}{0}Documents{0}Dispensing_Simulation.txt"
                       .format(os.sep, os.getlogin()), 'w', encoding="UTF-16")
        outfile.write(outstring)
        outfile.close()
Exemplo n.º 12
0
#SV200907 - module for simulating opentrons protocols

# Import statements
from opentrons.simulate import simulate, format_runlog

# Read file
protocol_file = open(
    "C:/Users/svreugdenhil/Documents/GitHub/OT2/mollab_protocols/primer_aliquots/illu_primer.py"
)

# Simulate protocol
runlog, _bundle = simulate(protocol_file)

# Print runlog
print(format_runlog(runlog))
Exemplo n.º 13
0
# -*- coding: utf-8 -*-
"""
Created on Mon May 25 18:43:58 2020

@author: Trevor Ho
"""

#%% Simulation
from opentrons.simulate import simulate, format_runlog
protocol_filename = 'Test_script.py'  # TODO: change this for a new file
protocol_file = open(protocol_filename)
runlog = simulate(protocol_file, file_name='')
print(format_runlog(runlog[0]))  # Line modified compared to Opentrons Doc

#%% Export simulated log file for documentation

simulated_log_filename = protocol_filename.split('.py')[0] + '_log.txt'
simulated_log = open(simulated_log_filename, 'w+')
simulated_log.write(format_runlog(runlog[0]))
simulated_log.close()
Exemplo n.º 14
0
from opentrons import simulate, robot

filepath = "tpeng/OneDrive/OD__Universität/BA__Axmann/PlateScripts/"
outpath = "tpeng/OneDrive/OD__Universität/BA__Axmann/protocol_simulations/"

filename = "P03_OTV1_GlcGradientONECELL_BigFalconRack"

PC = False
print_output = False

if PC:
    header = "D:/"
else:
    header = "C:/Users/"

protocol_file = open(header + filepath + filename + ".py")

robot.reset()
runlog = simulate.simulate(protocol_file, file_name=filename + ".py")

protocol_file.close()

if print_output:
    print(simulate.format_runlog(runlog[0]))
else:
    file = open(header + outpath + filename + "_out.txt", "w")
    file.write(simulate.format_runlog(runlog[0]))
    file.close()

robot.reset()
Exemplo n.º 15
0
# Check the file

if len(args) != 2 or not args[1].lower().endswith('.py'):
    print(
        'Input file or path should be an OT-2 protocol written in APIv2 ending with .py'
    )
    sys.exit(2)

input_file = sys.argv[1]

# Simulation

protocol_file = open(input_file)
runlog = simulate(protocol_file,
                  file_name='',
                  custom_labware_paths=['./labware_def/'])
print(format_runlog(runlog[0]))  # Line modified compared to Opentrons Doc

# Export simulated log file for documentation

simulated_log_filepath = "./protocol_log/" + input_file.split(
    '.py')[0] + '_log.txt'
simulated_log = open(simulated_log_filepath, 'w+')
simulated_log.write(format_runlog(runlog[0]))
simulated_log.close()

print(
    "Reminder: custom labware definitions in .json formats should be stored under ./labware_defs"
)
print("Log file created: " + simulated_log_filepath)