def simulationFPT(trajectorynum): ''' Calculates first passage time of a trajectory with random initial conditions and final state the trimer state :param trajectorynum: number of trajectories on which to calculate the FPT :return: state, first passage time ''' # Define dummy trajectory to extract bound states from python (needed to use getState function) dummyTraj = msmrd2.trajectories.patchyDimer2(2, 1) # Require more lax tolerances since trimer bends the dimer binding angle and shortens the distance # (can be tested this works very well by plotting with vmd). dummyTraj.setTolerances(0.50, 0.5 * 2 * np.pi) # Define simulation boundaries (choose either spherical or box) boxBoundary = msmrd2.box(boxsize, boxsize, boxsize, 'periodic') # Define potential potentialPatchyParticleAngular2 = patchyParticleAngular2( sigma, strength, angularStrength, patchesCoordinates) # Define integrator and boundary (over-damped Langevin) seed = int(-1 * trajectorynum) # Negative seed, uses random device as seed integrator = odLangevinSelective(dt, seed, bodytype) integrator.setBoundary(boxBoundary) integrator.setPairPotential(potentialPatchyParticleAngular2) # Generate random position and orientation particle list with two particles seed = int(trajectorynum) partlist = particleTools.randomParticleList(numparticles, boxsize, overlapThreshold, D, Drot, seed) # Set activePatchList for part in partlist: part.setActivePatchList(len(patchesCoordinates)) # Calculates the first passage times for the trime. 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
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 dummy trajectory to extract bound states from python (needed to use getState function) dummyTraj = msmrd2.trajectories.patchyDimer(2, 1, radialBounds[0], minimumUnboundRadius) # Define simulation boundaries (choose either spherical or box) boxBoundary = msmrd2.box(boxsize, boxsize, boxsize, 'periodic') # Define potential potentialPatchyParticleAngular = patchyParticleAngular(sigma, strength, angularStrength, patchesCoordinates) # Define integrator and boundary (over-damped Langevin) seed = int(-1*trajectorynum) # Negative seed, uses random device as seed integrator = odLangevin(dt, seed, bodytype) integrator.setBoundary(boxBoundary) integrator.setPairPotential(potentialPatchyParticleAngular) # Generate random position and orientation particle list with two particles seed = int(trajectorynum) partlist = generateParticleList(initialState, boxsize, D, Drot, seed) # Calculates the first passage times for a given bound state. Each trajectory is integrated until # the target bound state is reached. The output in the files is the elapsed time. intransition = True while(intransition): integrator.integrate(partlist) currentState = dummyTraj.getState(partlist[0], partlist[1]) if targetState == 'A' and currentState in boundStatesA: intransition = False return 'A', integrator.clock elif targetState == 'B' and currentState in boundStatesB: intransition = False return 'B', integrator.clock elif integrator.clock >= 10000.0: intransition = False return 'Failed at:', integrator.clock
boxsize = parameterDictionary['boxsize'] boundaryType = parameterDictionary['boundaryType'] # Calculated parameters #dtEffective = dt*stride # needed to obtain rate dictionary effectivetimeSteps = int(totalTimeSteps / stride) fnamebase = parentDirectory + 'simDimer_' bufferSize = effectivetimeSteps # Set trajectory discretizator #radialLowerBound = 1.25 #default values #radialUpperBound = 2.25 #default values discretizator = msmrd2.trajectories.patchyDimer(numParticles, bufferSize) # Set boundary (important for discretizer) boxBoundary = msmrd2.box(boxsize, boxsize, boxsize, boundaryType) discretizator.setBoundary(boxBoundary) # Loads H5 files and generates discrete trajectories at once directly on c++. dtrajs = [] for i in range(nfiles): filename = fnamebase + str(i).zfill(4) + '.h5' dtraj = discretizator.discretizeTrajectoryH5(filename) dtrajs.append(dtraj) print("Loading file ", i + 1, " of ", nfiles, " done.", end="\r") print("\nDone loading files") # Write discrete trajectory to xyz files for i, dtraj in enumerate(dtrajs): datafile = open(fnamebase + str(i).zfill(4) + '_discrete.xyz', 'w') for j in range(len(dtraj)):
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 dummy trajectory to extract bound states from python (needed to use getState function) dummyTraj = msmrd2.trajectories.patchyProtein(numparticles, 1024, radialBounds[0], minimumUnboundRadius) # 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 simulation boundaries (choose either spherical or box) boxBoundary = msmrd2.box(boxsize, boxsize, boxsize, 'periodic') # 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) # Generate random position and orientation particle list with two particles seed = int(trajectorynum) partlist = generateParticleList(initialState, boxsize, particleTypes, unboundMSMlist, randomSeed=-1) # 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. bound = True while (bound): integrator.integrate(partlist) boundState = dummyTraj.getState(partlist[0], partlist[1]) if boundState == 0: bound = False return initialState, integrator.clock elif integrator.clock >= 15000.0: bound = False return 'failed', integrator.clock
def MSMRDsimulationFPT(initialState, finalState, 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 :param initialState: initial bound state :param finalState final bound state :return: initial bound state, final bound state and 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 = generateParticleList(initialState, boxsize, particleTypes, couplingMSM, seed) # Calculates the first passage times from initialState to finalState. Each trajectory is integrated until # a finalState is reached or until it times out. The output in the files is the elapsed time. searchingEndState = True while(searchingEndState): integrator.integrate(partlist) currentState = partlist[0].boundState if currentState == finalState: searchingEndState = False return initialState, finalState, integrator.clock elif integrator.clock >= 15000.0: searchingEndState = False return 'failed', 'failed', 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