Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-n', '--n_trajs', help='number of trajectories. Default=10', type=int, default=10)
    parser.add_argument('-t', '--traj_length', help='trajectories length. Default=10000', type=int, default=10000)
    args = parser.parse_args()
    
    # these could be configured
    kT = 15.0
    dt = 0.1
    mGamma = 1000.0
    
    forcecalculator = muller.muller_force()
    

    project = Project({'ConfFilename': os.path.join(mullermsm.__path__[0], 'conf.pdb'),
              'NumTrajs': args.n_trajs,
              'ProjectRootDir': '.',
              'TrajFileBaseName': 'trj',
              'TrajFilePath': 'Trajectories',
              'TrajFileType': '.lh5',
              'TrajLengths': [args.traj_length]*args.n_trajs})
              
              
    if os.path.exists('ProjectInfo.h5'):
        print >> sys.stderr, "The file ./ProjectInfo.h5 already exists. I don't want to overwrite anything, so i'm backing off"
        sys.exit(1)
    
    
    try:
        os.mkdir('Trajectories')
    except OSError:
        print >> sys.stderr, "The directory ./Trajectores already exists. I don't want to overwrite anything, so i'm backing off"
        sys.exit(1)
        
    for i in range(args.n_trajs):
        print 'simulating traj %s' % i
        
        # select initial configs randomly from a 2D box
        initial_x = [random.uniform(-1.5, 1.2), random.uniform(-0.2, 2)]
        print 'starting conformation from randomly sampled points (%s, %s)' % (initial_x[0], initial_x[1])
        print 'propagating for %s steps on the Muller potential with a Langevin integrator...' % args.traj_length
        
        positions = muller.propagate(args.traj_length, initial_x, kT, dt, mGamma, forcecalculator)

        # positions is N x 2, but we want to make it N x 1 x 3 where the additional
        # column is just zeros. This way, being N x 1 x 3, it looks like a regular MD
        # trajectory that would be N_frames x N_atoms x 3
        positions3 = np.hstack((positions, np.zeros((len(positions),1)))).reshape((len(positions), 1, 3))
        t = Trajectory.LoadTrajectoryFile(project['ConfFilename'])
        t['XYZList'] = positions3
        
        t.SaveToLHDF(project.GetTrajFilename(i))
        print 'saving trajectory to %s' % project.GetTrajFilename(i)
        
    project.SaveToHDF('ProjectInfo.h5')
    print 'saved ProjectInfo.h5 file'

    
    pickle.dump(metric.EuclideanMetric(), open('metric.pickl', 'w'))
    print 'saved metric.pickl'
Ejemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-g', '--generators', default='Data/Gens.lh5', help='Path to Gens.lh5')
    parser.add_argument('-p', '--project', default='ProjectInfo.h5', help='Path to ProjectInfo.h5')
    parser.add_argument('-s', '--stride', default=5, type=int, help='Stride to plot the data at')
    args = parser.parse_args()
    
    
    gens = Trajectory.LoadTrajectoryFile(args.generators)
    gens_x = gens['XYZList'][:,0,0]
    gens_y =  gens['XYZList'][:,0,1]
    points = np.array([gens_x, gens_y]).transpose()
    
    
    
    tri = Delaunay(points)

    PL = []
    for p in points:
        PL.append(Voronoi.Site(x=p[0],y=p[1]))

    v,eqn,edges,wtf = Voronoi.computeVoronoiDiagram(PL)

    edge_points=[]
    for (l,x1,x2) in edges:
        if x1>=0 and x2>=0:
            edge_points.append((v[x1],v[x2]))

    lines = LineCollection(edge_points, linewidths=0.5, color='k')
    
    fig = pp.figure()
    ax = fig.add_subplot(111)
    
    fig.gca().add_collection(lines)

    maxx, minx= np.max(gens_x), np.min(gens_x)
    maxy, miny = np.max(gens_y), np.min(gens_y)
    # plot the background
    plot_v(minx=minx, maxx=maxx, miny=miny, maxy=maxy, ax=ax)
    pp.xlim(minx, maxx)
    pp.ylim(miny, maxy)

    # plot a single trajectory
    p = Project.LoadFromHDF(args.project)
    t = p.LoadTraj(0)
    x = t['XYZList'][:,0,0][::args.stride]
    y = t['XYZList'][:,0,1][::args.stride]
    cm = pp.get_cmap('spectral')

    n_points = len(x)
    ax.set_color_cycle([cm(1.*i/(n_points-1)) for i in range(n_points-1)])
    for i in range(n_points-1):
        ax.plot(x[i:i+2],y[i:i+2])

    pp.title('Voronoi Microstate Decomposition, with first trajectory')
    


    pp.show()
Ejemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', '--project', default='ProjectInfo.h5')
    parser.add_argument(
        '-t',
        '--trajectories',
        nargs='+',
        help='''Supply either the path to a trajectory file (i.e. Data/Gens.lh5),
         or an integer, which will be interepreted as a trajectory index
         into the trajectories that accompany the project. default: plot all
         of the trajectories''',
        default=['-1'])
    args = parser.parse_args()

    p = Project.LoadFromHDF(args.project)

    # record the bounding box of the points so that we know
    # what to render for the background
    maxx, minx, maxy, miny = 1.2, -1.5, 2, -0.2

    # if -1 is included, add in ALL of the trajectories
    if '-1' in args.trajectories:
        args.trajectories.remove('-1')
        args.trajectories.extend(range(p['NumTrajs']))
    # remove duplicates
    args.trajectories = set(args.trajectories)

    for requested in args.trajectories:
        if os.path.exists(str(requested)):
            traj = Trajectory.LoadTrajectoryFile(str(requested))
            print 'plotting %s' % requested
            markersize = 50
        else:
            try:
                i = int(requested)
                traj = p.LoadTraj(i)
                print 'plotting %s' % i
                markersize = 5
            except ValueError:
                print >> sys.stderr, 'I couldnt figure out how to deal with the argument %s' % requested
                continue
            except IOError as e:
                print >> sys.stderr, str(e)
                continue

        xyz = traj['XYZList']
        x = xyz[:, 0, 0]
        y = xyz[:, 0, 1]

        maxx, maxy = max(np.max(x), maxx), max(np.max(y), maxy)
        minx, miny = min(np.min(x), minx), min(np.min(y), miny)
        pp.plot(x, y, '.', markersize=markersize, alpha=0.5)

    plot_v(minx=minx, maxx=maxx, miny=miny, maxy=maxy)
    pp.show()