Exemple #1
0
def set_raw_alignment(name, aln, transform=0):
    '''
DESCRIPTION

    API only.
    Load an alignment object from a list like the one obtained with
    cmd.get_raw_alignment
    '''
    import itertools
    if not isinstance(aln[0], dict):
        aln = [dict(idx_pair) for idx_pair in aln]
    models = set(model for idx_pdict in aln for model in idx_pdict)
    sele1 = cmd.get_unused_name('_sele1')
    sele2 = cmd.get_unused_name('_sele2')
    fit = cmd.fit if transform else cmd.rms_cur
    for model1, model2 in itertools.combinations(models, 2):
        index_list1 = []
        index_list2 = []
        for idx_pdict in aln:
            if model1 in idx_pdict and model2 in idx_pdict:
                index_list1.append(idx_pdict[model1])
                index_list2.append(idx_pdict[model2])
        cmd.select_list(sele1, model1, index_list1, mode='index')
        cmd.select_list(sele2, model2, index_list2, mode='index')
        fit(sele1, sele2, cycles=0, matchmaker=4, object=name)
    cmd.delete(sele1)
    cmd.delete(sele2)
Exemple #2
0
def set_raw_alignment(name, aln, transform=0):
    '''
DESCRIPTION

    API only.
    Load an alignment object from a list like the one obtained with
    cmd.get_raw_alignment
    '''
    import itertools
    if not isinstance(aln[0], dict):
        aln = [dict(idx_pair) for idx_pair in aln]
    models = set(model for idx_pdict in aln for model in idx_pdict)
    sele1 = cmd.get_unused_name('_sele1')
    sele2 = cmd.get_unused_name('_sele2')
    fit = cmd.fit if transform else cmd.rms_cur
    for model1, model2 in itertools.combinations(models, 2):
        index_list1 = []
        index_list2 = []
        for idx_pdict in aln:
            if model1 in idx_pdict and model2 in idx_pdict:
                index_list1.append(idx_pdict[model1])
                index_list2.append(idx_pdict[model2])
        cmd.select_list(sele1, model1, index_list1, mode='index')
        cmd.select_list(sele2, model2, index_list2, mode='index')
        fit(sele1, sele2, cycles=0, matchmaker=4, object=name)
    cmd.delete(sele1)
    cmd.delete(sele2)
Exemple #3
0
    def from_alignment(self, mobile, target, aln_obj):
        '''
        Use alignment given by "aln_obj" (name of alignment object)
        '''
        from .selecting import wait_for
        wait_for(aln_obj)

        self.mobile = '(%s) and %s' % (mobile, aln_obj)
        self.target = '(%s) and %s' % (target, aln_obj)
        if self.check():
            return

        # difficult: if selections spans only part of the alignment or
        # if alignment object covers more than the two objects, then we
        # need to pick those columns that have no gap in any of the two
        # given selections

        mobileidx = set(cmd.index(mobile))
        targetidx = set(cmd.index(target))
        mobileidxsel = []
        targetidxsel = []

        for column in cmd.get_raw_alignment(aln_obj):
            mobiles = mobileidx.intersection(column)
            if len(mobiles) == 1:
                targets = targetidx.intersection(column)
                if len(targets) == 1:
                    mobileidxsel.extend(mobiles)
                    targetidxsel.extend(targets)

        self.mobile = cmd.get_unused_name('_mobile')
        self.target = cmd.get_unused_name('_target')
        self.temporary.append(self.mobile)
        self.temporary.append(self.target)

        mobile_objects = set(idx[0] for idx in mobileidxsel)
        target_objects = set(idx[0] for idx in targetidxsel)

        if len(mobile_objects) == len(target_objects) == 1:
            mobile_index_list = [idx[1] for idx in mobileidxsel]
            target_index_list = [idx[1] for idx in targetidxsel]
            cmd.select_list(self.mobile,
                            mobile_objects.pop(),
                            mobile_index_list,
                            mode='index')
            cmd.select_list(self.target,
                            target_objects.pop(),
                            target_index_list,
                            mode='index')
        else:
            cmd.select(self.mobile,
                       ' '.join('%s`%d' % idx for idx in mobileidxsel))
            cmd.select(self.target,
                       ' '.join('%s`%d' % idx for idx in targetidxsel))
Exemple #4
0
def select_distances(names='',
                     name='sele',
                     state=1,
                     selection='all',
                     cutoff=-1,
                     quiet=1):
    '''
DESCRIPTION

    Turns a distance object into a named atom selection.

ARGUMENTS

    names = string: names of distance objects (no wildcards!) {default: all
    measurement objects}

    name = a unique name for the selection {default: sele}

    state = int: object state (-1: current, 0: all states) {default: 1}

SEE ALSO

    get_raw_distances
    '''
    from collections import defaultdict
    _assert_package_import()
    from .querying import get_raw_distances

    state, cutoff, quiet = int(state), float(cutoff), int(quiet)
    states = [state] if state else list(
        range(1,
              cmd.count_states(selection) + 1))

    sele_dict = defaultdict(set)
    for state in states:
        distances = get_raw_distances(names, state, selection)
        for idx1, idx2, dist in distances:
            if cutoff <= 0.0 or dist <= cutoff:
                sele_dict[idx1[0]].add(idx1[1])
                sele_dict[idx2[0]].add(idx2[1])

    cmd.select(name, 'none')
    tmp_name = cmd.get_unused_name('_')

    r = 0
    for model in sele_dict:
        cmd.select_list(tmp_name, model, list(sele_dict[model]), mode='index')
        r = cmd.select(name, tmp_name, merge=1)
        cmd.delete(tmp_name)

    if not quiet:
        print(' Selector: selection "%s" defined with %d atoms.' % (name, r))
    return r
Exemple #5
0
    def from_alignment(self, mobile, target, aln_obj):
        '''
        Use alignment given by "aln_obj" (name of alignment object)
        '''
        from .selecting import wait_for
        wait_for(aln_obj)

        self.mobile = '(%s) and %s' % (mobile, aln_obj)
        self.target = '(%s) and %s' % (target, aln_obj)
        if self.check():
            return

        # difficult: if selections spans only part of the alignment or
        # if alignment object covers more than the two objects, then we
        # need to pick those columns that have no gap in any of the two
        # given selections

        mobileidx = set(cmd.index(mobile))
        targetidx = set(cmd.index(target))
        mobileidxsel = []
        targetidxsel = []

        for column in cmd.get_raw_alignment(aln_obj):
            mobiles = mobileidx.intersection(column)
            if len(mobiles) == 1:
                targets = targetidx.intersection(column)
                if len(targets) == 1:
                    mobileidxsel.extend(mobiles)
                    targetidxsel.extend(targets)

        self.mobile = cmd.get_unused_name('_mobile')
        self.target = cmd.get_unused_name('_target')
        self.temporary.append(self.mobile)
        self.temporary.append(self.target)

        mobile_objects = set(idx[0] for idx in mobileidxsel)
        target_objects = set(idx[0] for idx in targetidxsel)

        if len(mobile_objects) == len(target_objects) == 1:
            mobile_index_list = [idx[1] for idx in mobileidxsel]
            target_index_list = [idx[1] for idx in targetidxsel]
            cmd.select_list(self.mobile, mobile_objects.pop(), mobile_index_list, mode='index')
            cmd.select_list(self.target, target_objects.pop(), target_index_list, mode='index')
        else:
            cmd.select(self.mobile, ' '.join('%s`%d' % idx for idx in mobileidxsel))
            cmd.select(self.target, ' '.join('%s`%d' % idx for idx in targetidxsel))
Exemple #6
0
def select_distances(names='', name='sele', state=1, selection='all', cutoff=-1, quiet=1):
    '''
DESCRIPTION

    Turns a distance object into a named atom selection.

ARGUMENTS

    names = string: names of distance objects (no wildcards!) {default: all
    measurement objects}

    name = a unique name for the selection {default: sele}

    state = int: object state (-1: current, 0: all states) {default: 1}

SEE ALSO

    get_raw_distances
    '''
    from collections import defaultdict
    from .querying import get_raw_distances

    state, cutoff, quiet = int(state), float(cutoff), int(quiet)
    states = [state] if state else list(range(1, cmd.count_states(selection)+1))

    sele_dict = defaultdict(set)
    for state in states:
        distances = get_raw_distances(names, state, selection)
        for idx1, idx2, dist in distances:
            if cutoff <= 0.0 or dist <= cutoff:
                sele_dict[idx1[0]].add(idx1[1])
                sele_dict[idx2[0]].add(idx2[1])

    cmd.select(name, 'none')
    tmp_name = cmd.get_unused_name('_')

    r = 0
    for model in sele_dict:
        cmd.select_list(tmp_name, model, list(sele_dict[model]), mode='index')
        r = cmd.select(name, tmp_name, merge=1)
        cmd.delete(tmp_name)

    if not quiet:
        print(' Selector: selection "%s" defined with %d atoms.' % (name, r))
    return r
Exemple #7
0
def select_distances(names='',
                     name='sele',
                     state=1,
                     selection='all',
                     cutoff=-1,
                     quiet=1):
    '''
DESCRIPTION

    Turns a distance object into a named atom selection.

ARGUMENTS

    names = string: names of distance objects (no wildcards!) {default: all
    measurement objects}

    name = a unique name for the selection {default: sele}

SEE ALSO

    get_raw_distances
    '''
    state, cutoff, quiet = int(state), float(cutoff), int(quiet)

    sele_dict = {}
    distances = get_raw_distances(names, state, selection)
    for idx1, idx2, dist in distances:
        if cutoff <= 0.0 or dist <= cutoff:
            sele_dict.setdefault(idx1[0], set()).add(idx1[1])
            sele_dict.setdefault(idx2[0], set()).add(idx2[1])

    cmd.select(name, 'none')
    tmp_name = cmd.get_unused_name('_')

    r = 0
    for model in sele_dict:
        cmd.select_list(tmp_name, model, list(sele_dict[model]), mode='index')
        r = cmd.select(name, tmp_name, merge=1)
        cmd.delete(tmp_name)

    if not quiet:
        print((' Selector: selection "%s" defined with %d atoms.' % (name, r)))
    return r
Exemple #8
0
def _promix(conformers=0,
            prefix=None,
            obj=NotImplemented,
            selection=NotImplemented,
            X=NotImplemented,
            K=NotImplemented,
            Mixture=NotImplemented,
            **_):

    if not prefix:
        if conformers:
            prefix = obj + '_conformer'
        else:
            prefix = obj + '_segment'
    cmd.delete(prefix + '_*')

    id_list = []
    cmd.iterate(selection, 'id_list.append(ID)', space=locals())

    mixture = Mixture.new(X, K)
    membership = mixture.membership

    if conformers:
        states_list = [0] * mixture.K
        for (i, k) in enumerate(membership):
            states_list[k] += 1
            name = '%s_%d' % (prefix, k + 1)
            cmd.create(name, obj, i + 1, states_list[k])
    else:
        cmd.color('gray', selection)
        for k in range(mixture.K):
            name = '%s_%d' % (prefix, k + 1)
            id_list_k = [i for (i, m) in zip(id_list, membership) if m == k]
            cmd.select_list(name, obj, id_list_k)
            cmd.disable(name)
            cmd.color(k + 2, name)

    for k, (sigma, w) in enumerate(zip(mixture.sigma, mixture.w)):
        print(' %s_%d: sigma = %6.3f, w = %.3f' % (prefix, k + 1, sigma, w))

    print(' BIC: %.2f' % (mixture.BIC))
    print(' Log Likelihood: %.2f' % (mixture.log_likelihood))
def set_raw_alignment(name, aln, transform=0, guide=''):
    '''
DESCRIPTION

    API only.
    Load an alignment object from a list like the one obtained with
    cmd.get_raw_alignment

SEE ALSO

    cmd.set_raw_alignment in PyMOL 2.3
    '''
    if hasattr(cmd, 'set_raw_alignment') and not int(transform):
        return cmd.set_raw_alignment(name, aln, guide=guide)

    if not isinstance(aln[0], dict):
        aln = [dict(idx_pair) for idx_pair in aln]
    models = set(model for idx_pdict in aln for model in idx_pdict)
    sele1 = cmd.get_unused_name('_sele1')
    sele2 = cmd.get_unused_name('_sele2')
    fit = cmd.fit if transform else cmd.rms_cur

    if guide:
        models.remove(guide)
        model2 = guide
    else:
        model2 = models.pop()

    for model1 in models:
        index_list1 = []
        index_list2 = []
        for idx_pdict in aln:
            if model1 in idx_pdict and model2 in idx_pdict:
                index_list1.append(idx_pdict[model1])
                index_list2.append(idx_pdict[model2])
        cmd.select_list(sele1, model1, index_list1, mode='index')
        cmd.select_list(sele2, model2, index_list2, mode='index')
        fit(sele1, sele2, cycles=0, matchmaker=4, object=name)
    cmd.delete(sele1)
    cmd.delete(sele2)
Exemple #10
0
def set_raw_alignment(name, aln, transform=0, guide=''):
    '''
DESCRIPTION

    API only.
    Load an alignment object from a list like the one obtained with
    cmd.get_raw_alignment

SEE ALSO

    cmd.set_raw_alignment in PyMOL 2.3
    '''
    if hasattr(cmd, 'set_raw_alignment') and not int(transform):
        return cmd.set_raw_alignment(name, aln, guide=guide)

    if not isinstance(aln[0], dict):
        aln = [dict(idx_pair) for idx_pair in aln]
    models = set(model for idx_pdict in aln for model in idx_pdict)
    sele1 = cmd.get_unused_name('_sele1')
    sele2 = cmd.get_unused_name('_sele2')
    fit = cmd.fit if transform else cmd.rms_cur

    if guide:
        models.remove(guide)
        model2 = guide
    else:
        model2 = models.pop()

    for model1 in models:
        index_list1 = []
        index_list2 = []
        for idx_pdict in aln:
            if model1 in idx_pdict and model2 in idx_pdict:
                index_list1.append(idx_pdict[model1])
                index_list2.append(idx_pdict[model2])
        cmd.select_list(sele1, model1, index_list1, mode='index')
        cmd.select_list(sele2, model2, index_list2, mode='index')
        fit(sele1, sele2, cycles=0, matchmaker=4, object=name)
    cmd.delete(sele1)
    cmd.delete(sele2)
Exemple #11
0
def missing_c_termini(selection="(all)", quiet=0, _self=cmd):
    cmd = _self
    # assumes that hydogens are not present!

    sele_list = []
    ch = Champ()
    model = cmd.get_model(selection)
    model_pat = ch.insert_model(model)
    assn_pat = ch.insert_pattern_string("[N+0+1]C[C;D2]<0>(=O)")
    ch.pattern_clear_tags(model_pat)
    if ch.match_1v1_n(assn_pat, model_pat, 10000, 2) > 0:
        result = ch.pattern_get_ext_indices_with_tags(model_pat)
        for atom_tag in result[0]:  # just iterate over atom tags
            if len(atom_tag[1]) == 1:  # one and only one match
                if atom_tag[1][0] == 0:
                    sele_list.append(atom_tag[0])
    cmd.select_list(tmp_sele1, selection, sele_list, mode='index')
    while cmd.pop(tmp_sele2, tmp_sele1) > 0:  # complete the carboxy terminus
        cmd.edit(tmp_sele2)
        cmd.attach("O", 1, 1, "OXT", quiet=1)
        cmd.unpick()
    cmd.delete(tmp_sele1)
Exemple #12
0
def missing_c_termini(selection="(all)",quiet=0,_self=cmd):
    cmd=_self
    # assumes that hydogens are not present!
    
    sele_list = []
    ch=Champ()
    model = cmd.get_model(selection)
    model_pat = ch.insert_model(model)
    assn_pat = ch.insert_pattern_string("[N+0+1]C[C;D2]<0>(=O)")
    ch.pattern_clear_tags(model_pat)
    if ch.match_1v1_n(assn_pat,model_pat,10000,2)>0:
        result = ch.pattern_get_ext_indices_with_tags(model_pat)
        for atom_tag in result[0]: # just iterate over atom tags
            if len(atom_tag[1])==1: # one and only one match
                if atom_tag[1][0]==0:
                    sele_list.append(atom_tag[0])
    cmd.select_list(tmp_sele1,selection,sele_list, mode='index')
    while cmd.pop(tmp_sele2,tmp_sele1)>0: # complete the carboxy terminus
        cmd.edit(tmp_sele2)
        cmd.attach("O",1,1,"OXT",quiet=1)
        cmd.unpick()
    cmd.delete(tmp_sele1)
Exemple #13
0
def _promix(conformers=0, prefix=None,
        obj=NotImplemented, selection=NotImplemented,
        X=NotImplemented, K=NotImplemented, Mixture=NotImplemented,
        **_):

    if not prefix:
        if conformers:
            prefix = obj + '_conformer'
        else:
            prefix = obj + '_segment'
    cmd.delete(prefix + '_*')

    id_list = []
    cmd.iterate(selection, 'id_list.append(ID)', space=locals())

    mixture = Mixture.new(X, K)
    membership = mixture.membership

    if conformers:
        states_list = [0] * mixture.K
        for (i,k) in enumerate(membership):
            states_list[k] += 1
            name = '%s_%d' % (prefix, k+1)
            cmd.create(name, obj, i+1, states_list[k])
    else:
        cmd.color('gray', selection)
        for k in range(mixture.K):
            name = '%s_%d' % (prefix, k+1)
            id_list_k = [i for (i, m) in zip(id_list, membership) if m == k]
            cmd.select_list(name, obj, id_list_k)
            cmd.disable(name)
            cmd.color(k + 2, name)

    for k, (sigma, w) in enumerate(zip(mixture.sigma, mixture.w)):
        print(' %s_%d: sigma = %6.3f, w = %.3f' % (prefix, k+1, sigma, w))

    print(' BIC: %.2f' % (mixture.BIC))
    print(' Log Likelihood: %.2f' % (mixture.log_likelihood))
def select_distances(names='', name='sele', state=1, selection='all', cutoff=-1, quiet=1):
    '''
DESCRIPTION

    Turns a distance object into a named atom selection.

ARGUMENTS

    names = string: names of distance objects (no wildcards!) {default: all
    measurement objects}

    name = a unique name for the selection {default: sele}

SEE ALSO

    get_raw_distances
    '''
    state, cutoff, quiet = int(state), float(cutoff), int(quiet)

    sele_dict = {}
    distances = get_raw_distances(names, state, selection)
    for idx1, idx2, dist in distances:
        if cutoff <= 0.0 or dist <= cutoff:
            sele_dict.setdefault(idx1[0], set()).add(idx1[1])
            sele_dict.setdefault(idx2[0], set()).add(idx2[1])

    cmd.select(name, 'none')
    tmp_name = cmd.get_unused_name('_')

    r = 0
    for model in sele_dict:
        cmd.select_list(tmp_name, model, list(sele_dict[model]), mode='index')
        r = cmd.select(name, tmp_name, merge=1)
        cmd.delete(tmp_name)

    if not quiet:
        print((' Selector: selection "%s" defined with %d atoms.' % (name, r)))
    return r