Exemplo n.º 1
0
def iRED_full(mol,
              rank=2,
              n=100,
              nr=10,
              align_iRED=False,
              refVecs=None,
              **kwargs):
    """
    Runs the full iRED analysis for a given selection (or set of vec_special functions)
    Arguments are the rank (0 or 1), the sampling (n,nr), whether to align the 
    vectors (align_iRED='y'/'n', and refVecs, which may be a dict containing 
    a vector, created by DIFRATE, a tuple of strings selecting two sets of atoms
    defining bonds), or simply 'y', which will default to using the N-CA bonds in
    a protein.
    
    ired=iRED_full(mol,rank=2,n=100,nr=10,align_iRED='n',refVecs='n',**kwargs)
    
    """

    if 'nt' in kwargs:
        nt = np.min([mol.mda_object.trajectory.n_frames, kwargs.get('nt')])
    else:
        nt = mol.mda_object.trajectory.n_frames
    index = trunc_t_axis(nt, n, nr)
    vec = get_trunc_vec(mol, index, **kwargs)

    if align_iRED:
        if refVecs is not None:
            vec0 = refVecs
            if isinstance(vec0, dict):
                pass
            elif len(vec0) == 2 and isinstance(vec0[0], str) and isinstance(
                    vec0[1], str):
                mol1 = mol.copy()
                mol1.select_atoms(sel1=vec0[0], sel2=vec0[1])
                vec0 = get_trunc_vec(mol1, index)
            elif isinstance(vec0, str) and vec0.lower()[0] == 'y':
                s1 = 'protein and name CA and around 1.6 N'
                s2 = 'protein and name N and around 1.6 CA'
                mol1 = mol.copy()
                mol1.select_atoms(sel1=s1, sel2=s2)
                vec0 = get_trunc_vec(mol1, index)
            else:
                print(
                    'Warning: refVecs entry not valid, using input vectors as reference (without aligning)'
                )
                vec0 = vec
        else:
            vec0 = vec
    else:
        vec0 = None

    ired = vec2iRED(vec,
                    rank,
                    align_iRED,
                    refVecs=vec0,
                    molecule=mol,
                    **kwargs)

    return ired
Exemplo n.º 2
0
def Ct_S2(molecule, n=100, nr=10, **kwargs):
    nt = molecule.mda_object.trajectory.n_frames

    index = trunc_t_axis(nt, n, nr)

    vec = get_trunc_vec(molecule, index, **kwargs)

    ct = Ct(vec, **kwargs)

    S2 = S2calc(vec)

    return ct, S2
Exemplo n.º 3
0
def mol2vec(mol, n=100, nr=10, tf=None, dt=None, index=None):
    """
    Extracts vectors describing from the frame functions found in the molecule
    object. Arguments are mol, the molecule object, n and nr, which are parameters
    specifying sparse sampling, and dt, which overrides dt found in the trajectory
    """

    traj = mol.mda_object.trajectory
    if tf is None: tf = traj.n_frames
    if index is None:
        index = trunc_t_axis(tf, n, nr)

    return ini_vec_load(traj,
                        mol._vf,
                        mol._vft,
                        mol._frame_info['frame_index'],
                        index=index,
                        dt=dt)
Exemplo n.º 4
0
def Ct2data(molecule, n=100, nr=10, **kwargs):
    """
    data=Ct2data(molecule,n=100,nr=10,**kwargs)
    Takes a molecule object (generated from an MD trajectory), and creates a
    data object, where the data contains elements of the correlation function,
    where the trajectory has been sparsely sampled (according to arguments n
    and nr)
    """

    mol = molecule
    if 'nt' in kwargs:
        nt = np.min([mol.mda_object.trajectory.n_frames, kwargs.get('nt')])
    else:
        nt = mol.mda_object.trajectory.n_frames

    index = trunc_t_axis(nt, n, nr)

    vec = get_trunc_vec(mol, index, **kwargs)

    Ctdata = vec2data(vec, molecule=mol, **kwargs)
    return Ctdata
Exemplo n.º 5
0
    def __init__(self, tc=None, z=None, t=None, **kwargs):
        """Probably a better way to do this, but I need to identify which
        child of mdl_sens is which later. Using isinstance requires me to 
        import the children into mdl_sens, but also import mdl_sens into its
        children. This seems to create some strange dependence so that I can't
        actually load any of the classes any more"""

        self._class = 'Ct'
        self._origin = 'Ct'
        """The detectors class may have bond-specific sensitivities in _rho. We
        need to know if this is the case for the mdl_sens class to work 
        properly
        """
        self._BondSpfc = 'no'
        """Get user defined tc if provided. Options are to provide the tc 
        vector directly, to provide the log directly (define z instead of tc), 
        or to specify it as a start, end, and number of steps, which are then 
        log-spaced (3 entries for tc or z)
        """

        if tc is None:
            if z is not None:
                if np.size(z) == 3:
                    self.__tc = np.logspace(z[0], z[1], z[2])
                else:
                    self.__tc = np.power(10, z)
                "Allow users to input z instead of tc"
            else:
                self.__tc = np.logspace(-14, -3, 200)
        elif np.size(tc) == 3:
            self.__tc = np.logspace(np.log10(tc[0]), np.log10(tc[1]), tc[2])
        else:
            self.__tc = np.array(tc)
        """We don't allow editing of the tc vector; you must initialize a new 
        instance of rates if you want to change it"""
        """If you want to edit the code to include new experiments, and these 
        require new variables, they MUST be added to one of these lists
        """

        "We need to initialize self.info"
        self.info = None

        a = dict()
        if t is not None:
            if np.size(t) == 3:
                self.__t = np.arange(t[0], t[1], t[2])
            elif np.size(t) == 2:
                self.__t = np.arange(0, t[0], t[1])
            else:
                self.__t = t
        elif 'sparse' in kwargs:
            "Include nt, n, nr and dt in dict object"
            sparse = kwargs.get('sparse')
            if 'dt' not in sparse or 'nt' not in sparse:
                print(
                    'dt and nt are required arguments for generating a sparse sensitivity object'
                )
                return
            index = trunc_t_axis(**sparse)

            "Get the count of number of averages"
            N = get_count(index)

            t = sparse.get('dt') * np.arange(index[-1] + 1)
            i = N != 0
            N = N[i]
            self.__t = t[i]

            if 'stdev' not in kwargs:
                stdev = 1 / np.sqrt(N)
                stdev[0] = 1e-6
                kwargs.update({'stdev': stdev})
        else:
            self.__t = np.arange(0, 500.001, .005)

        a.update({'t': self.__t})

        nt = self.__t.size

        if 'stdev' in kwargs:
            stdev = kwargs.get('stdev')
            if np.size(stdev) == 1:
                vec = 1 / np.sqrt(np.arange(nt, 0, -1))
                vec = vec / vec[0]
                stdev = vec * stdev
                stdev[0] = 1e-6
            elif np.size(stdev) != np.size(self.__t):
                vec = 1 / np.sqrt(np.arange(nt, 0, -1))
                stdev = vec / vec[-1]
                stdev[0] = 1e-6
        else:
            vec = 1 / np.sqrt(np.arange(nt, 0, -1))
            stdev = vec / vec[-1]
            stdev[0] = 1e-6
        a.update({'stdev': stdev})

        if 'median_val' in kwargs:
            median_val = kwargs.get('median_val')
            if np.size(median_val) == 1:
                median_val = np.ones(nt) * median_val
        else:
            median_val = np.ones(nt)
        a.update({'median_val': median_val})

        self.info = pd.DataFrame.from_dict(a).T

        if 'S2' in kwargs:
            #            self.__R=np.exp(-1e-9*np.dot(np.atleast_2d(self.__t).T,1/np.atleast_2d(self.__tc)))\
            #                -np.repeat([np.exp(-1e-9*self.__t[-1]/self.__tc)],self.__t.shape[0],axis=0)
            "Note the new formula for sensitivity after S2 subtraction. Based on Poisson distribution"
            T = self.__t[-1] * 1e-9  #Length of the trajectory
            Lambda = 1. / (2. * self.__tc)  #Constant for Poisson distribution
            self.__R=np.exp(-1e-9*np.dot(np.atleast_2d(self.__t).T,1/np.atleast_2d(self.__tc)))\
                -np.repeat([1./(T*Lambda)*(1-np.exp(-T*Lambda))],self.__t.shape[0],axis=0)
        else:
            self.__R = np.exp(-1e-9 * np.dot(
                np.atleast_2d(self.__t).T, 1 / np.atleast_2d(self.__tc)))
#            self.__R=np.exp(-1e-9*np.dot(np.transpose([self.__t]),np.divide(1,[self.__tc])))
        "Names of the experimental variables that are available"
        self.__exper = ['t', 'stdev']
        "Names of the spin system variables that are available"
        self.__spinsys = []

        super().__init__()