def runParallelSims(simnumber): # Define seed seed = int(simnumber) random.seed(seed) # Create unbound MSMlist (CTMSMs) # MSM for particle type0 MSMtype = 0 markovModel0 = ctmsm(MSMtype, -1 * seed) # random variable seed D0list = np.array([1.0]) Drot0list = np.array([1.0]) markovModel0.setD(D0list) markovModel0.setDrot(Drot0list) # MSM for particle type1 MSMtype = 1 ratematrix = np.array([[-0.5, 0.5], [6.0, -6.0]]) markovModel1 = ctmsm(MSMtype, ratematrix, -2 * seed) D1list = np.array([0.5, 1.0]) Drot1list = np.array([0.5, 1.0]) markovModel1.setD(D1list) markovModel1.setDrot(Drot1list) unboundMSMlist = [markovModel0, markovModel1] # Define boundary boxBoundary = msmrd2.box(boxsize, boxsize, boxsize, boundaryType) # Define particle list particleList = particleTools.randomParticleMSList(Nparticles, boxsize, separationDistance, particleTypes, unboundMSMlist, seed) # Defines patchy protein potential potentialPatchyProteinMS = patchyProteinMarkovSwitch( sigma, strength, angularStrength, patchesCoordinates1, patchesCoordinates2) # Integrator definition seed = int( -1 * simnumber ) # random seed (negative and different for every simulation, good for parallelization) integrator = odLangevinMS(unboundMSMlist, dt, seed, bodytype) integrator.setBoundary(boxBoundary) integrator.setPairPotential(potentialPatchyProteinMS) # Creates simulation sim = msmrd2.simulation(integrator) # Output filename definition filename = basefilename + "_{:04d}".format(simnumber) # Runs simulation sim.run(particleList, timesteps, stride, bufferSize, filename, outTxt, outH5, outChunked, trajtype) print("Simulation " + str(simnumber) + ", done.")
def simulationFPT(trajectorynum): ''' Calculates first passage time of a trajectory with random initial conditions and final state a bound state :param trajectorynum: number of trajectories on which to calculate the FPT :return: state, first passage time ''' # Define simulation boundaries (choose either spherical or box) boxBoundary = msmrd2.box(boxsize, boxsize, boxsize, 'periodic') # Define dummy trajectory to extract bound states from python (needed to use getState function) radialLowerBound = 1.25 radialUpperBound = 2.25 dummyTraj = msmrd2.trajectories.patchyProtein(numparticles, 1024, radialLowerBound, radialUpperBound) dummyTraj.setBoundary(boxBoundary) # Define base seed seed = int(-1 * trajectorynum) # Negative seed, uses random device as seed # Create unbound MSMlist (CTMSMs) # MSM for particle type0 MSMtype = 0 markovModel0 = ctmsm(MSMtype, -1 * seed) # random variable seed D0list = np.array([1.0]) Drot0list = np.array([1.0]) markovModel0.setD(D0list) markovModel0.setDrot(Drot0list) # MSM for particle type1 MSMtype = 1 ratematrix = np.array([[-0.5, 0.5], [6.0, -6.0]]) markovModel1 = ctmsm(MSMtype, ratematrix, -2 * seed) D1list = np.array([0.5, 1.0]) Drot1list = np.array([0.5, 1.0]) markovModel1.setD(D1list) markovModel1.setDrot(Drot1list) unboundMSMlist = [markovModel0, markovModel1] # Define potential potentialPatchyProtein = patchyProteinMarkovSwitch(sigma, strength, angularStrength, patchesCoordinates1, patchesCoordinates2) # Define integrator and boundary (over-damped Langevin) integrator = odLangevinMS(unboundMSMlist, dt, seed, bodytype) integrator.setBoundary(boxBoundary) integrator.setPairPotential(potentialPatchyProtein) # Creates random particle list seed = int(trajectorynum) partlist = particleTools.randomParticleMSList(numparticles, boxsize, minimumUnboundRadius, particleTypes, unboundMSMlist, seed) # Calculates the first passage times for a given bound state. Each trajectory is integrated until # a bound state is reached. The output in the files is the elapsed time. unbound = True while (unbound): integrator.integrate(partlist) boundState = dummyTraj.getState(partlist[0], partlist[1]) if boundState in boundStates: unbound = False return boundState, integrator.clock elif integrator.clock >= 15000.0: unbound = False return 'Failed at:', integrator.clock
def MSMRDsimulationFPT(trajectorynum): ''' Calculates first passage time of a trajectory with random initial conditions and final state a bound state :param trajectorynum: trajectory number (index on parallel computation) on which to calculate the FPT :return: state, first passage time ''' # Define discretization discretization = msmrd2.discretizations.positionOrientationPartition( radialBounds[1], numSphericalSectionsPos, numRadialSectionsQuat, numSphericalSectionsQuat) discretization.setThetasOffset(np.pi / 4.0) # Define boundary boxBoundary = msmrd2.box(boxsize, boxsize, boxsize, 'periodic') # Define isotropic potential (no patches) potentialPatchyProtein = patchyProteinMarkovSwitch(sigma, strength, angularStrength, patchesCoordinates1, patchesCoordinates2) # Define base seed seed = int(-1 * trajectorynum) # Negative seed, uses random device as seed # Load rate dicitionary pickle_in = open( MSMdirectory + "MSM_patchyProtein_t6.00E+06_s25_lagt" + str(lagtime) + ".pickle", "rb") mainMSM = pickle.load(pickle_in) tmatrix = mainMSM['transition_matrix'] activeSet = mainMSM['active_set'] # Create unbound MSMlist (CTMSMs) # MSM for particle type0 MSMtype = 0 markovModel0 = ctmsm(MSMtype, -1 * seed) # random variable seed D0list = np.array([1.0]) Drot0list = np.array([1.0]) markovModel0.setD(D0list) markovModel0.setDrot(Drot0list) # MSM for particle type1 MSMtype = 1 ratematrix = np.array([[-0.5, 0.5], [6.0, -6.0]]) markovModel1 = ctmsm(MSMtype, ratematrix, -2 * seed) D1list = np.array([0.5, 1.0]) Drot1list = np.array([0.5, 1.0]) markovModel1.setD(D1list) markovModel1.setDrot(Drot1list) unboundMSMlist = [markovModel0, markovModel1] # Set coupling MSM for MSM/RD seed = int(-3 * trajectorynum) # Negative seed, uses random device as seed couplingMSM = msmrdMSM(numBoundStates, maxNumBoundStates, tmatrix, activeSet, realLagtime, seed) couplingMSM.setDbound(Dbound, DboundRot) # Define integrator, boundary and discretization seed = -int(1 * trajectorynum) # Negative seed, uses random device as seed integrator = msmrdPatchyProtein(dt, seed, bodytype, numParticleTypes, radialBounds, unboundMSMlist, couplingMSM) integrator.setBoundary(boxBoundary) integrator.setDiscretization(discretization) integrator.setPairPotential(potentialPatchyProtein) # Creates random particle list seed = int(trajectorynum) partlist = particleTools.randomParticleMSList(numparticles, boxsize, minimumUnboundRadius, particleTypes, unboundMSMlist, seed) # Calculates the first passage times for a given bound state. Each trajectory is integrated until # a bound state is reached. The output in the files is the elapsed time. unbound = True while (unbound): integrator.integrate(partlist) currentState = partlist[0].boundState if currentState in boundStates: unbound = False #filenameLog = filename = "../../data/patchyProtein/eventLog_" + str(trajectorynum) #integrator.printEventLog(filenameLog) return currentState, integrator.clock elif integrator.clock >= 15000.0: unbound = False return 'Failed at:', integrator.clock
def MSMRDsimulationFPT(trajectorynum): ''' Calculates first passage time of a trajectory with random initial conditions and final state a bound state :param trajectorynum: trajectory number (index on parallel computation) on which to calculate the FPT :return: state, first passage time ''' # Define discretization discretization = msmrd2.discretizations.positionOrientationPartition( radialBounds[1], numSphericalSectionsPos, numRadialSectionsQuat, numSphericalSectionsQuat) # Define boundary boxBoundary = msmrd2.box(boxsize, boxsize, boxsize, 'periodic') # Load rate dicitionary pickle_in = open( MSMdirectory + "MSM_patchyDimer_t3.00E+06_s25_lagt" + str(lagtime) + ".pickle", "rb") mainMSM = pickle.load(pickle_in) tmatrix = mainMSM['transition_matrix'] activeSet = mainMSM['active_set'] # Set unbound MSM seed = int(-2 * trajectorynum) # Negative seed, uses random device as seed unboundMSM = ctmsm(MSMtype, ratematrix, seed) unboundMSM.setD(Dlist) unboundMSM.setDrot(Drotlist) # Set coupling MSM seed = int(-3 * trajectorynum) # Negative seed, uses random device as seed couplingMSM = msmrdMSM(numBoundStates, maxNumBoundStates, tmatrix, activeSet, realLagtime, seed) couplingMSM.setDbound(Dbound, DboundRot) # Define integrator, boundary and discretization seed = -int(1 * trajectorynum) # Negative seed, uses random device as seed integrator = msmrdIntegrator(dt, seed, bodytype, numParticleTypes, radialBounds, unboundMSM, couplingMSM) integrator.setBoundary(boxBoundary) integrator.setDiscretization(discretization) # Generate random position and orientation particle list with two particles seed = int(trajectorynum) partlist = particleTools.randomParticleMSList(numParticles, boxsize, minimumUnboundRadius, partTypes, [unboundMSM], seed) # Calculates the first passage times for a given bound state. Each trajectory is integrated until # a bound state is reached. The output in the files is the elapsed time. unbound = True while (unbound): integrator.integrate(partlist) currentState = partlist[0].boundState if currentState in boundStatesA: unbound = False return 'A', integrator.clock elif currentState in boundStatesB: unbound = False return 'B', integrator.clock elif integrator.clock >= 10000.0: unbound = False return 'Failed at:', integrator.clock
def MSMRDsimulationFPT(trajectorynum): ''' Calculates first passage time of a trajectory with random initial conditions and final state a bound state :param trajectorynum: trajectory number (index on parallel computation) on which to calculate the FPT :return: state, first passage time ''' # Define discretization discretization = msmrd2.discretizations.positionOrientationPartition( radialBounds[1], numSphericalSectionsPos, numRadialSectionsQuat, numSphericalSectionsQuat) # Define boundary boxBoundary = msmrd2.box(boxsize, boxsize, boxsize, 'periodic') # Load rate dicitionary pickle_in = open( "../../data/pentamer/MSMs/MSM_dimerForPentamer_t3.00E+06_s25_lagt" + str(lagtime) + ".pickle", "rb") # Same MSM as trimer mainMSM = pickle.load(pickle_in) tmatrix = mainMSM['transition_matrix'] activeSet = mainMSM['active_set'] # Set unbound MSM seed = int(-2 * trajectorynum) # Negative seed, uses random device as seed unboundMSM = ctmsm(MSMtype, ratematrix, seed) unboundMSM.setD(Dlist) unboundMSM.setDrot(Drotlist) # Set coupling MSM seed = int(-3 * trajectorynum) # Negative seed, uses random device as seed couplingMSM = msmrdMSM(numBoundStates, maxNumBoundStates, tmatrix, activeSet, realLagtime, seed) couplingMSM.setDbound(Dbound, DboundRot) # Define integrator, boundary and discretization seed = -int(1 * trajectorynum) # Negative seed, uses random device as seed integrator = msmrdMultiParticleIntegrator(dt, seed, bodytype, numParticleTypes, radialBounds, unboundMSM, couplingMSM, DlistCompound, DrotlistCompound) integrator.setBoundary(boxBoundary) integrator.setDiscretization(discretization) # Generate random position and orientation particle list with two particles seed = int(trajectorynum) partlist = particleTools.randomParticleMSList(numParticles, boxsize, minimumUnboundRadius, partTypes, [unboundMSM], seed) # Calculates the first passage times to a given bound state. Each trajectory is integrated until # a bound state is reached. The output in the files is the elapsed time. unbound = True ii = 0 while (unbound): ii += 1 integrator.integrate(partlist) # Check status every 5000 timesteps (adds possible error of up to 5000*dt = 0.5), but # speeds up simulations if (ii % 5000 == 0): ringFormations = integrator.findClosedBindingLoops(partlist) if (3 in ringFormations): unbound = False return 'trimeric-loop', integrator.clock elif (4 in ringFormations): unbound = False return 'tetrameric-loop', integrator.clock elif (5 in ringFormations): unbound = False return "pentameric-loop", integrator.clock elif integrator.clock >= 400.0: unbound = False return 'Failed at:', integrator.clock