Ejemplo n.º 1
0
 def plot_contact_map(self, name, selection="noh and protein", data=None, threshold=4):
     """Generate a residue-residue contact plot by macrostate given a VMD selection
     
     Parameters
     ----------
     name : str
         Output name for the generated plot
     selection : str, optional
         VMD selection to create a matrix contact plot
     threshold : int, optional
         Threshold distance in angstrom to discrinate contact vs no-contact
     """
     from htmd.projections.metricdistance import MetricDistance
     contact_metric = MetricDistance(sel1=selection, sel2=selection,
         groupsel1="residue", groupsel2="residue", threshold=threshold, metric="contacts")
     
     mapping = contact_metric.getMapping(self.mol)
     aux_plot(self.model, self.mol, contact_plot, metric=contact_metric, skip=self.skip, method=np.mean,
              mapping=mapping, cols=2, rows=int(self.model.macronum/2)+self.model.macronum%2, data=data,
              plot=False, save=f"{self.out_folder}/{name}.png")
Ejemplo n.º 2
0
    def plot_atom_mol_contact(self, data=None, sel1="noh and protein", sel2="noh and resname MOL", threshold=5):
        """Plot a molecule-residue contact map.
        
        Parameters
        ----------
        sel1 : str, optional
            VMD selection. Grouped by residue.
        sel2 : str, optional
            VMD selection
        threshold : int, optional
            Threshold distance in angstrom to discrinate contact vs no-contact
        """
        from htmd.projections.metricdistance import MetricDistance

        label = ['M{}-{}%'.format(i, np.round(percent*100, 2)) for i, percent in enumerate(self.model.eqDistribution(plot=False))]
        mol_contact_map_metric = MetricDistance(sel1=sel1, sel2=sel2,
            groupsel1="residue", threshold=threshold, metric="contacts")
        mapping = mol_contact_map_metric.getMapping(self.mol)

        aux_plot(self.model, self.mol, contact_plot_by_atom, metric=mol_contact_map_metric, 
                 skip=self.skip, method=np.mean, data=data,
                 mapping=mapping, label=label, save=f'{self.out_folder}/{self.plot_mol_contacts}_by_atom.png')
Ejemplo n.º 3
0
    def plot_mol_contact(self, data=None, sel1="noh and protein", sel2="noh and resname MOL", threshold=4):
        """Plot a molecule-residue contact map.
        
        Parameters
        ----------
        sel1 : str, optional
            VMD selection. Grouped by residue.
        sel2 : str, optional
            VMD selection
        threshold : int, optional
            Threshold distance in angstrom to discrinate contact vs no-contact
        """
        from htmd.projections.metricdistance import MetricDistance
        # labels = generate_labels(self.mol)
        mol_contact_map_metric = MetricDistance(sel1=sel1, sel2=sel2, 
            groupsel1="residue", groupsel2="all", threshold=5, metric="contacts")

        # mapping = mol_contact_map_metric.getMapping(self.mol)
        aux_plot(self.model, self.mol, plot_contacts, metric=mol_contact_map_metric, skip=self.skip, method=np.mean,
            title="Contacts by residue", data=data,
            plot=False, save=f'{self.out_folder}/{self.plot_mol_contacts}.png')
Ejemplo n.º 4
0
    def rmsdgoal(proj):
        return -proj  # Lower RMSDs should give higher score

    tmpdir = tempname()
    shutil.copytree(htmd.home.home() + '/data/adaptive/', tmpdir)
    os.chdir(tmpdir)
    md = AdaptiveGoal()
    md.dryrun = True
    md.nmin = 1
    md.nmax = 2
    md.nepochs = 3
    md.ticalag = 2
    md.ticadim = 3
    md.updateperiod = 5
    md.projection = MetricDistance('protein and name CA',
                                   'resname BEN and noh')
    # md.goalprojection = MetricRmsd(Molecule(htmd.home() + '/data/adaptive/generators/1/structure.pdb'),
    #                               'protein and name CA')
    md.goalfunction = rmsdgoal
    # md.app = AcemdLocal()
    # md.run()

    # Some real testing now
    from htmd.projections.metricsecondarystructure import MetricSecondaryStructure
    from htmd.projections.metricdistance import MetricSelfDistance
    import numpy as np

    os.chdir(path.join(home(), 'data', 'test-adaptive'))

    goalProjectionDict = {
        'ss':
Ejemplo n.º 5
0
    from htmd.projections.metricdistance import MetricDistance
    from htmd.projections.metricdihedral import MetricDihedral
    from htmd.util import tempname
    from htmd.home import home
    from os.path import join

    testfolder = home(dataDir='adaptive')

    sims = simlist(glob(join(testfolder, 'data', '*', '')),
                   glob(join(testfolder, 'input', '*', 'structure.pdb')))
    fsims = simfilter(sims, tempname(), 'not water')
    metr = Metric(fsims)
    metr.set(
        MetricDistance('protein and resid 10 and name CA',
                       'resname BEN and noh',
                       metric='contacts',
                       groupsel1='residue',
                       threshold=4))
    data1 = metr.project()
    metr.set(MetricDihedral())
    data2 = metr.project()

    # Testing combining of metrics
    data1.combine(data2)

    # Testing dimensions
    assert np.array_equal(data1.description.shape,
                          (897, 3)), 'combine not working correct'
    assert np.array_equal(data1.trajectories[0].projection.shape,
                          (6, 897)), 'combine not working correct'
    assert np.array_equal(
Ejemplo n.º 6
0
    def _algorithm(self):
        logger.info('Postprocessing new data')
        datalist = simlist(
            glob(path.join(self.datapath, '*', '')),
            glob(path.join(self.inputpath, '*', 'structure.pdb')),
            glob(path.join(self.inputpath, '*', '')))
        filtlist = simfilter(datalist,
                             self.filteredpath,
                             filtersel=self.filtersel)

        if hasattr(self, 'metricsel2') and self.metricsel2 is not None:
            proj = MetricDistance(self.metricsel1,
                                  self.metricsel2,
                                  metric=self.metrictype)
        else:
            proj = MetricSelfDistance(self.metricsel1, metric=self.metrictype)
        metr = Metric(filtlist, skip=self.skip)
        metr.projection(proj)
        data = metr.project()

        #if self.contactsym is not None:
        #    contactSymmetry(data, self.contactsym)

        data.dropTraj()
        if self.ticadim > 0:
            tica = TICA(data, int(max(2, np.ceil(20 / self.skip))))
            datadr = tica.project(self.ticadim)
        else:
            datadr = data

        K = int(
            max(np.round(0.6 * np.log10(datadr.numFrames / 1000) * 1000 + 50),
                100))  # heuristic
        if K > datadr.numFrames / 3:  # Freaking ugly patches ...
            K = int(datadr.numFrames / 3)

        datadr.cluster(self.clustmethod(n_clusters=K), mergesmall=5)
        replacement = False
        if datadr.K < 10:
            datadr.cluster(self.clustmethod(n_clusters=K))
            replacement = True

        model = Model(datadr)
        macronum = self.macronum
        if datadr.K < macronum:
            macronum = np.ceil(datadr.K / 2)
            logger.warning(
                'Using less macrostates than requested due to lack of microstates. macronum = '
                + str(macronum))

        from pyemma.msm import timescales_msm
        timesc = timescales_msm(datadr.St.tolist(),
                                lags=self.lag,
                                nits=macronum).get_timescales()
        macronum = min(self.macronum, max(np.sum(timesc > self.lag), 2))

        model.markovModel(self.lag, macronum)
        p_i = self._criteria(model, self.method)
        (spawncounts, prob) = self._spawn(p_i, self.nmax - self.running)
        logger.debug('spawncounts {}'.format(spawncounts))
        stateIdx = np.where(spawncounts > 0)[0]
        _, relFrames = model.sampleStates(stateIdx,
                                          spawncounts[stateIdx],
                                          statetype='micro',
                                          replacement=replacement)
        logger.debug('relFrames {}'.format(relFrames))

        self._writeInputs(datadr.rel2sim(np.concatenate(relFrames)))
Ejemplo n.º 7
0
        aux_plot(self.model, self.mol, plot_contacts, metric=mol_contact_map_metric, normalize=False, skip=self.skip, method=np.mean,
            mod=self.model, title="Contacts by residue", vmax=None,
            plot=False, save=f'{self.out_folder}/no_sasa_test.png')

if __name__ == '__main__':
    from htmd.projections.metricdistance import MetricDistance
    from htmd.model import Model

    mt = ModelAnalysis("/workspace8/excitome/adaptiveRun/O75376_MOR_58/",
        "/home/pablo/testModel/")

    mt.metrics = [
                MetricDistance(
                sel1="noh and protein",
                sel2="noh and protein",
                metric="contacts",
                threshold=5,
                groupsel1="residue",
                groupsel2="residue")
            ]

    model = Model()
    model.load("/home/pablo/testModel/model.dat")
    mt.model = model
    mt.handle_model()
    mt.sasa_variation()
    # mt.model = "/home/pablo/testModel/model.dat"
    # mt.plot_dihedral = "2_dihedral"
    # mt.macronum = 4
    # mt.plot_contacts = [
    #     ('all_contacts', 'noh and protein', 5),
Ejemplo n.º 8
0
    from htmd.projections.metricdistance import MetricDistance
    from htmd.model import Model
    from htmd.molecule.molecule import Molecule
    import numpy as np

    data = MetricData()
    data.load(
        "/workspace8/p27_sj403/10-11-2018_p27_short_sj403/analysis/17_11_2018/testing.dat"
    )
    model = Model()
    model.load(
        "/workspace8/p27_sj403/10-11-2018_p27_short_sj403/analysis/17_11_2018/model.dat"
    )
    mol = Molecule(model.data.simlist[0].molfile)
    mean_dat = getStateStatistic(model, data, range(model.macronum))
    met = MetricDistance(sel1="noh and protein or resname MOL",
                         sel2="noh and protein or resname MOL",
                         groupsel1="residue",
                         groupsel2="residue",
                         metric="distances",
                         pbc=False)
    mapping = met.getMapping(mol)
    contact_plot(mean_dat,
                 mol,
                 rows=2,
                 cols=2,
                 model=model,
                 plot=False,
                 save="/home/pablo/test.png",
                 mapping=mapping)