示例#1
0
#!/usr/bin/env python
 
from schwancrtools import ArgLib_E

options, prep_metric = ArgLib_E.parse(['projectfn'],new_arglist=[('outFN','-o','--out','outputfilename to save covariance matrix to. Will use Serializer.SaveData','./CovMat.h5')],metric_parsers=True)
 
from msmbuilder import Project, Serializer
import numpy as np
from schwancrtools import complexPCA
from pyschwancr import dataIO
import os, sys, re
 
Proj = Project.LoadFromHDF(options.projectfn)

cov_matrix = None
N = 0

for i in xrange(Proj['NumTrajs']):
    print "Working on trajectory %d" % i
    ptraj = prep_metric.prepare_trajectory( Proj.LoadTraj(i) ).astype(complex)

    n_rows, n_cols = ptraj.shape

    temp_cov_matrix = np.zeros( ( n_cols, n_cols ) ).astype(complex)

    if not ptraj.flags.contiguous:
        ptraj = ptraj.copy()
        if not ptraj.flags.contiguous:
            print "ptraj and ptraj.copy() are not contiguous arrays... Something wierd is going on."

    complexPCA.get_covariance( ptraj, temp_cov_matrix )
示例#2
0
#!/usr/bin/env python
import numpy as np
from msmbuilder import Serializer, Project
import os, sys, re
from schwancrtools import ArgLib_E

options, prep_metric = ArgLib_E.parse(['projectfn','pcaobject'],new_arglist=[('pc_n','-N','--n-pc','Which eigenvector to project onto.', 0), ('outFN','--out','--output','output filename. Will use np.save',None) ], metric_parsers=True)

print "Using %s to prepare the trajectory. This should NOT be a pca metric" % str( prep_metric.__repr__() )


Proj = Project.LoadFromHDF( options.projectfn )
pca = Serializer.LoadFromHDF( options.pcaobject )

dec_ind = np.argsort( pca['vals'] )[::-1]

which_vec = int( options.pc_n )

v = pca['vecs'][ :, dec_ind[which_vec] ]

print v.shape
data = []

for i in xrange( Proj['NumTrajs'] ):
    print "Working on trajectory %d" % i
    traj = Proj.LoadTraj( i )
    ptraj = prep_metric.prepare_trajectory( traj )
    ptraj = ptraj.conj() * v
    ptraj = ptraj.sum(axis=1)
    data.extend( ptraj )