<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 AdaptiveMD
Example 6 - Multi-traj
0. Imports
Step1:  Alright, let's load the package and pick the Project since we want to start a project
Step2:  Let's open a project with a UNIQUE name. This will be the name used in the DB so make sure it is new and not too short. Opening a project will always create a non-existing project and reopen an exising one. You cannot chose between opening types as you would with a file. This is a precaution to not accidentally delete your project.
Step3:  Now we have a handle for our project. First thing is to set it up to work on a resource.
1. Set the resource
What is a resource? A Resource specifies a shared filesystem with one or more clusteres attached to it. This can be your local machine or just a regular cluster or even a group of cluster that can access the same FS (like Titan, Eos and Rhea do).
Once you have chosen your place to store your results this way it is set for the project and can (at least should) not be altered since all file references are made to match this resource. Currently you can use the Fu Berlin Allegro Cluster or run locally. There are two specific local adaptations that include already the path to your conda installation. This simplifies the use of openmm or pyemma.
Let us pick a local resource on a laptop for now.
Step4:  first pick your resource -- where you want to run your simulation. Local or on Allegro
Step5:  2. Add TaskGenerators
TaskGenerators are instances whose purpose is to create tasks to be executed. This is similar to the
way Kernels work. A TaskGenerator will generate Task objects for you which will be translated into a ComputeUnitDescription and executed. In simple terms
Step6:  The engine
Step7:  3. Create one intial trajectory
Create a Trajectory object
Step8:  That is all we can do from here. To execute the tasks you need to run a worker using
bash
adaptivemdworker -l tutorial --verbose
Step9:  Once this is done, come back here and check your results. If you want you can execute the next cell which will block until the task has been completed.
Step10:  and close the project.
<ASSISTANT_TASK:>
Python Code:
import sys, os
Explanation: AdaptiveMD
Example 6 - Multi-traj
0. Imports
End of explanation
from adaptivemd import Project
Explanation: Alright, let's load the package and pick the Project since we want to start a project
End of explanation
# Use this to completely remove the example-worker project from the database.
Project.delete('tutorial-multi')
project = Project('tutorial-multi')
Explanation: Let's open a project with a UNIQUE name. This will be the name used in the DB so make sure it is new and not too short. Opening a project will always create a non-existing project and reopen an exising one. You cannot chose between opening types as you would with a file. This is a precaution to not accidentally delete your project.
End of explanation
from adaptivemd import LocalCluster, AllegroCluster
Explanation: Now we have a handle for our project. First thing is to set it up to work on a resource.
1. Set the resource
What is a resource? A Resource specifies a shared filesystem with one or more clusteres attached to it. This can be your local machine or just a regular cluster or even a group of cluster that can access the same FS (like Titan, Eos and Rhea do).
Once you have chosen your place to store your results this way it is set for the project and can (at least should) not be altered since all file references are made to match this resource. Currently you can use the Fu Berlin Allegro Cluster or run locally. There are two specific local adaptations that include already the path to your conda installation. This simplifies the use of openmm or pyemma.
Let us pick a local resource on a laptop for now.
End of explanation
resource = LocalCluster()
project.initialize(resource)
Explanation: first pick your resource -- where you want to run your simulation. Local or on Allegro
End of explanation
from adaptivemd.engine.openmm import OpenMMEngine
from adaptivemd import File, Directory
Explanation: 2. Add TaskGenerators
TaskGenerators are instances whose purpose is to create tasks to be executed. This is similar to the
way Kernels work. A TaskGenerator will generate Task objects for you which will be translated into a ComputeUnitDescription and executed. In simple terms:
The task generator creates the bash scripts for you that run a simulation or run pyemma.
A task generator will be initialized with all parameters needed to make it work and it will now what needs to be staged to be used.
End of explanation
pdb_file = File('file://../files/alanine/alanine.pdb').named('initial_pdb').load()
engine = OpenMMEngine(
    pdb_file=pdb_file,
    system_file=File('file://../files/alanine/system.xml').load(),
    integrator_file=File('file://../files/alanine/integrator.xml').load(),
    args='-r --report-interval 1 -p CPU'
).named('openmm')
engine.add_output_type('master', 'master.dcd', 10)
engine.add_output_type('protein', 'protein.dcd', 1)
engine.types
project.generators.add(engine)
s = engine._create_output_str()
print s
task = project.new_trajectory(pdb_file, 100, engine=engine).run()
Explanation: The engine
End of explanation
project.queue(task)  # shortcut for project.tasks.add(task)
Explanation: 3. Create one intial trajectory
Create a Trajectory object
End of explanation
print project.tasks
task.trajectory
task.state
t = project.trajectories.one
t.types['protein']
Explanation: That is all we can do from here. To execute the tasks you need to run a worker using
bash
adaptivemdworker -l tutorial --verbose
End of explanation
print project.files
print project.trajectories
Explanation: Once this is done, come back here and check your results. If you want you can execute the next cell which will block until the task has been completed.
End of explanation
project.close()
Explanation: and close the project.
End of explanation
<END_TASK>