Пример #1
0
def simulate_single_mab(single_molecule, number_of_steps, groups, group_masks,
                        number_of_groups, residues_in_groups,
                        rotation_variables, dihedral_parameters,
                        flexible_residues, residue_rotation_indices,
                        residue_rotation_mask, step_parameters,
                        first_last_resid, cutoff):

    frame = 0

    seed = [1, 2]
    seed = [0, 2]

    if (seed[0] == 1):
        from numpy.random import RandomState
        seed_object = RandomState(seed[1])
    else:
        seed_object = -1
    nonbondflag = False

    backward = True
    rotate_type = 'protein_backbone_dihedral'

    molecule_type = rotation_variables[0]
    temperature = rotation_variables[1]
    basis = rotation_variables[2]
    number_of_ranges = rotation_variables[3]
    reslow = rotation_variables[4]
    numcont = rotation_variables[5]
    dtheta = rotation_variables[6]

    kb = 1.380658E-23  # J/K
    beta = 1.0 / (temperature * kb)

    pairdat = ['dum', 1, 1.0]

    dcdoutfile = single_molecule.open_dcd_write('adum.dcd')
    coor = single_molecule.coor()
    taccepted = 0
    nsteps = 0
    count = 0

    # debugging

    da_outfile = open('dangles.txt', 'w')

    # end debugging

    for i in xrange(number_of_steps):

        print '.',
        sys.stdout.flush()

        vdi, vdf, indices, this_mask = step_parameters.chooser(
            coor, single_molecule, pairdat, dtheta, number_of_ranges, reslow,
            numcont, dihedral_parameters, beta, residue_rotation_indices,
            residue_rotation_mask, nonbondflag, first_last_resid,
            molecule_type, seed_object)

        angle = pairdat[0]
        residue_to_rotate = pairdat[1]
        theta = pairdat[2]

        # debugging

        #angle = 'psi'
        #residue_to_rotate = 5
        #theta = 5.0 * numpy.pi/180.0

        # end debugging

        # HARDWIRED
        if (residue_to_rotate < 7):
            this_group = groups[0]
            this_mask = group_masks[0]
            group_to_rotate = 0
        else:
            this_group = groups[1]
            this_mask = group_masks[1]
            group_to_rotate = 1

        group_rotation.rotate_a_group(this_group, rotate_type,
                                      residue_to_rotate, angle, theta,
                                      backward)
        check = check_ball_overlap(single_molecule, this_group,
                                   group_to_rotate, cutoff)

        if (check == 0):

            # debugging

            if (angle == 'psi'):

                basis = '(resid[i] == ' + str(
                    residue_to_rotate
                ) + ' and (name[i] == "N" or name[i] == "CA" or name[i] == "C")) or (resid[i] == ' + str(
                    residue_to_rotate + 1) + ' and (name[i] == "C") )'
                error, mask = single_molecule.get_subset_mask(basis)
                check_error(error)

                error, temp_coor = single_molecule.get_coor_using_mask(
                    frame, mask)
                check_error(error)
                lcoor = temp_coor[0]
                d_angle = sasmath.dihedral_angle(lcoor[0], lcoor[1], lcoor[2],
                                                 lcoor[3])
                print 'initial dihedral angle = ', d_angle
                da_outfile.write("%lf\n" % (d_angle))
                da_outfile.flush()

            # end debugging

            single_molecule.set_coor_using_mask(this_group, frame, this_mask)

            # debugging

            if (angle == 'psi'):
                error, temp_coor = single_molecule.get_coor_using_mask(
                    frame, mask)
                check_error(error)
                lcoor = temp_coor[0]
                d_angle = sasmath.dihedral_angle(lcoor[0], lcoor[1], lcoor[2],
                                                 lcoor[3])
                print 'final dihedral angle = ', d_angle

                port = 54321
                flag = 0
                single_molecule.send_coordinates_to_vmd(port, flag)

            # end debugging

            single_molecule.write_dcd_step(dcdoutfile, 0, taccepted + 1)
            taccepted += 1
        else:
            #			if(count == 10):
            #				print '.',
            #				dcdfile2 = dum_molecule.open_dcd_read('adum.dcd')
            #				nf=dcdfile2[2]
            #				my_frame = random.randint(0,nf)
            #				for j in xrange(my_frame):
            #					dum_molecule.read_dcd_step(dcdfile2,my_frame)
            #				dum_coor = dum_molecule.coor()[0]
            #				single_molecule.coor()[0] = dum_coor
            #				count = 0
            count += 1

        nsteps += 1

    return
Пример #2
0
def measure(coor, indices, an, this_mask, q0, first_last_resid, molecule_type):

    ind = numpy.nonzero(this_mask * numpy.arange(1, len(this_mask) + 1))[0]
    this_frame_coor = coor[0, :, :]

    lcoor = numpy.take(this_frame_coor[:, :], ind, 0)

    error = []

    if (molecule_type == 'protein'):

        if (an == 'phi'):
            angle = sasmath.dihedral_angle(lcoor[0, :], lcoor[1, :],
                                           lcoor[2, :], lcoor[3, :])
        elif (an == 'psi'):
            if (q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(lcoor[0, :], lcoor[1, :],
                                               lcoor[2, :], lcoor[3, :])
            else:
                angle = sasmath.dihedral_angle(lcoor[1, :], lcoor[2, :],
                                               lcoor[3, :], lcoor[4, :])
        else:
            angle = 0.0
            message = 'error (in rotate.measure): no phi/psi angle specified'
            error.append(message)
            print 'unknown angle specified: %s\nnow exiting' % an
            sys.exit()


#
# OPEN	Stub for error handling
#
    elif (molecule_type == 'rna'):

        if (an == 'alpha'):
            angle = sasmath.dihedral_angle(lcoor[0, :], lcoor[1, :],
                                           lcoor[2, :], lcoor[3, :])
        elif (an == 'beta'):
            if (q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(lcoor[0, :], lcoor[1, :],
                                               lcoor[2, :], lcoor[3, :])
            else:
                angle = sasmath.dihedral_angle(lcoor[1, :], lcoor[2, :],
                                               lcoor[3, :], lcoor[4, :])
        elif (an == 'gamma'):
            if (q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(lcoor[1, :], lcoor[2, :],
                                               lcoor[3, :], lcoor[4, :])
            else:
                angle = sasmath.dihedral_angle(lcoor[2, :], lcoor[3, :],
                                               lcoor[4, :], lcoor[5, :])
        elif (an == 'delta'):
            if (q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(lcoor[2, :], lcoor[3, :],
                                               lcoor[4, :], lcoor[5, :])
            else:
                angle = sasmath.dihedral_angle(lcoor[3, :], lcoor[4, :],
                                               lcoor[5, :], lcoor[6, :])
        elif (an == 'epsilon'):
            if (q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(lcoor[3, :], lcoor[4, :],
                                               lcoor[5, :], lcoor[6, :])
            else:
                angle = sasmath.dihedral_angle(lcoor[4, :], lcoor[5, :],
                                               lcoor[6, :], lcoor[7, :])
        elif (an == 'eta'):
            if (q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(lcoor[4, :], lcoor[5, :],
                                               lcoor[6, :], lcoor[7, :])
            else:
                angle = sasmath.dihedral_angle(lcoor[5, :], lcoor[6, :],
                                               lcoor[7, :], lcoor[8, :])
        else:
            angle = 0.0
            message = 'error (in rotate.measure): no alpha/beta/delta/epsilon/eta angle specified'
            error.append(message)
            print 'unknown angle specified: %s\nnow exiting' % an
            sys.exit()

    elif (molecule_type == 'dna'):
        if (first_last_resid[0] == first_last_resid[1]):
            print 'only given one base for calculating angles'
            print 'code needs revision in order to enable this'
            return 0
        i = {
            "O3'-1": 0,
            "P": 1,
            "O5'": 2,
            "C5'": 3,
            "C4'": 4,
            "O4'": 5,
            "C1'": 6,
            "chi3": 7,
            "chi4": 8,
            "C3'": 9,
            "O3'": 10,
            "P+1": 11,
            "O5'+1": 12
        }
        if q0 == first_last_resid[0] and len(lcoor) == 12:
            first_last_coor = numpy.zeros((13, 3))
            first_last_coor[1:] = lcoor
            lcoor = numpy.copy(first_last_coor)

        if (an == 'alpha'):
            if (q0 == first_last_resid[0]):
                angle = 0
            else:
                angle = sasmath.dihedral_angle(lcoor[i["O3'-1"], :],
                                               lcoor[i["P"], :],
                                               lcoor[i["O5'"], :],
                                               lcoor[i["C5'"], :])
        elif (an == 'beta'):
            angle = sasmath.dihedral_angle(lcoor[i["P"], :],
                                           lcoor[i["O5'"], :],
                                           lcoor[i["C5'"], :],
                                           lcoor[i["C4'"], :])
        elif (an == 'gamma'):
            angle = sasmath.dihedral_angle(lcoor[i["O5'"], :],
                                           lcoor[i["C5'"], :],
                                           lcoor[i["C4'"], :],
                                           lcoor[i["C3'"], :])
        elif (an == 'delta'):
            angle = sasmath.dihedral_angle(lcoor[i["C5'"], :],
                                           lcoor[i["C4'"], :],
                                           lcoor[i["C3'"], :],
                                           lcoor[i["O3'"], :])
        elif (an == 'epsilon'):
            if (q0 == first_last_resid[1]):
                angle = 0
            else:
                angle = sasmath.dihedral_angle(lcoor[i["C4'"], :],
                                               lcoor[i["C3'"], :],
                                               lcoor[i["O3'"], :],
                                               lcoor[i["P+1"], :])
        elif (an == 'zeta'):
            if (q0 == first_last_resid[1]):
                angle = 0
            else:
                angle = sasmath.dihedral_angle(lcoor[i["C3'"], :],
                                               lcoor[i["O3'"], :],
                                               lcoor[i["P+1"], :],
                                               lcoor[i["O5'+1"], :])
        elif (an == 'chi'):
            angle = sasmath.dihedral_angle(lcoor[i["O4'"], :],
                                           lcoor[i["C1'"], :],
                                           lcoor[i["chi3"], :],
                                           lcoor[i["chi4"], :])

        else:
            angle = 0.0
            message = 'error (in rotate.measure): no alpha/beta/delta/epsilon/eta angle specified'
            error.append(message)
            print 'unknown angle specified: %s\nnow exiting' % an

    return angle
Пример #3
0
def measure(coor, indices, an, this_mask, q0, first_last_resid, molecule_type):

    ind = numpy.nonzero(this_mask * numpy.arange(1, len(this_mask) + 1))[0]
    this_frame_coor = coor[0, :, :]

    lcoor = numpy.take(this_frame_coor[:, :], ind, 0)

    error = []

    if(molecule_type == 'protein'):

        if(an == 'phi'):
            angle = sasmath.dihedral_angle(
                lcoor[0, :], lcoor[1, :], lcoor[2, :], lcoor[3, :])
        elif(an == 'psi'):
            if(q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(
                    lcoor[0, :], lcoor[1, :], lcoor[2, :], lcoor[3, :])
            else:
                angle = sasmath.dihedral_angle(
                    lcoor[1, :], lcoor[2, :], lcoor[3, :], lcoor[4, :])
        else:
            angle = 0.0
            message = 'error (in rotate.measure): no phi/psi angle specified'
            error.append(message)
            print 'unknown angle specified: %s\nnow exiting' % an
            sys.exit()
#
# OPEN	Stub for error handling
#
    elif(molecule_type == 'rna'):

        if(an == 'alpha'):
            angle = sasmath.dihedral_angle(
                lcoor[0, :], lcoor[1, :], lcoor[2, :], lcoor[3, :])
        elif(an == 'beta'):
            if(q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(
                    lcoor[0, :], lcoor[1, :], lcoor[2, :], lcoor[3, :])
            else:
                angle = sasmath.dihedral_angle(
                    lcoor[1, :], lcoor[2, :], lcoor[3, :], lcoor[4, :])
        elif(an == 'gamma'):
            if(q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(
                    lcoor[1, :], lcoor[2, :], lcoor[3, :], lcoor[4, :])
            else:
                angle = sasmath.dihedral_angle(
                    lcoor[2, :], lcoor[3, :], lcoor[4, :], lcoor[5, :])
        elif(an == 'delta'):
            if(q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(
                    lcoor[2, :], lcoor[3, :], lcoor[4, :], lcoor[5, :])
            else:
                angle = sasmath.dihedral_angle(
                    lcoor[3, :], lcoor[4, :], lcoor[5, :], lcoor[6, :])
        elif(an == 'epsilon'):
            if(q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(
                    lcoor[3, :], lcoor[4, :], lcoor[5, :], lcoor[6, :])
            else:
                angle = sasmath.dihedral_angle(
                    lcoor[4, :], lcoor[5, :], lcoor[6, :], lcoor[7, :])
        elif(an == 'eta'):
            if(q0 == first_last_resid[0]):
                angle = sasmath.dihedral_angle(
                    lcoor[4, :], lcoor[5, :], lcoor[6, :], lcoor[7, :])
            else:
                angle = sasmath.dihedral_angle(
                    lcoor[5, :], lcoor[6, :], lcoor[7, :], lcoor[8, :])
        else:
            angle = 0.0
            message = 'error (in rotate.measure): no alpha/beta/delta/epsilon/eta angle specified'
            error.append(message)
            print 'unknown angle specified: %s\nnow exiting' % an
            sys.exit()

    elif(molecule_type == 'dna'):
        if(first_last_resid[0] == first_last_resid[1]):
            print 'only given one base for calculating angles'
            print 'code needs revision in order to enable this'
            return 0
        i = {"O3'-1": 0, "P": 1, "O5'": 2, "C5'": 3, "C4'": 4, "O4'": 5,
             "C1'": 6, "chi3": 7, "chi4": 8, "C3'": 9,
             "O3'": 10, "P+1": 11, "O5'+1": 12}
        if q0 == first_last_resid[0] and len(lcoor) == 12:
            first_last_coor = numpy.zeros((13, 3))
            first_last_coor[1:] = lcoor
            lcoor = numpy.copy(first_last_coor)

        if(an == 'alpha'):
            if(q0 == first_last_resid[0]):
                angle = 0
            else:
                angle = sasmath.dihedral_angle(
                    lcoor[i["O3'-1"], :], lcoor[i["P"], :], lcoor[i["O5'"], :], lcoor[i["C5'"], :])
        elif(an == 'beta'):
            angle = sasmath.dihedral_angle(
                lcoor[i["P"], :], lcoor[i["O5'"], :], lcoor[i["C5'"], :], lcoor[i["C4'"], :])
        elif(an == 'gamma'):
            angle = sasmath.dihedral_angle(
                lcoor[i["O5'"], :], lcoor[i["C5'"], :], lcoor[i["C4'"], :], lcoor[i["C3'"], :])
        elif(an == 'delta'):
            angle = sasmath.dihedral_angle(
                lcoor[i["C5'"], :], lcoor[i["C4'"], :], lcoor[i["C3'"], :], lcoor[i["O3'"], :])
        elif(an == 'epsilon'):
            if(q0 == first_last_resid[1]):
                angle = 0
            else:
                angle = sasmath.dihedral_angle(
                    lcoor[i["C4'"], :], lcoor[i["C3'"], :], lcoor[i["O3'"], :], lcoor[i["P+1"], :])
        elif(an == 'zeta'):
            if(q0 == first_last_resid[1]):
                angle = 0
            else:
                angle = sasmath.dihedral_angle(
                    lcoor[i["C3'"], :], lcoor[i["O3'"], :], lcoor[i["P+1"], :], lcoor[i["O5'+1"], :])
        elif(an == 'chi'):
            angle = sasmath.dihedral_angle(
                lcoor[i["O4'"], :], lcoor[i["C1'"], :], lcoor[i["chi3"], :], lcoor[i["chi4"], :])

        else:
            angle = 0.0
            message = 'error (in rotate.measure): no alpha/beta/delta/epsilon/eta angle specified'
            error.append(message)
            print 'unknown angle specified: %s\nnow exiting' % an

    return angle
Пример #4
0
def simulate_single_mab(single_molecule, number_of_steps, groups, group_masks, number_of_groups, residues_in_groups, rotation_variables, dihedral_parameters, flexible_residues, residue_rotation_indices, residue_rotation_mask, step_parameters, first_last_resid, cutoff):

    frame = 0

    seed = [1, 2]
    seed = [0, 2]

    if(seed[0] == 1):
        from numpy.random import RandomState
        seed_object = RandomState(seed[1])
    else:
        seed_object = -1
    nonbondflag = False

    backward = True
    rotate_type = 'protein_backbone_dihedral'

    molecule_type = rotation_variables[0]
    temperature = rotation_variables[1]
    basis = rotation_variables[2]
    number_of_ranges = rotation_variables[3]
    reslow = rotation_variables[4]
    numcont = rotation_variables[5]
    dtheta = rotation_variables[6]

    kb = 1.380658E-23  # J/K
    beta = 1.0 / (temperature * kb)

    pairdat = ['dum', 1, 1.0]

    dcdoutfile = single_molecule.open_dcd_write('adum.dcd')
    coor = single_molecule.coor()
    taccepted = 0
    nsteps = 0
    count = 0

    # debugging

    da_outfile = open('dangles.txt', 'w')

    # end debugging

    for i in xrange(number_of_steps):

        print '.',
        sys.stdout.flush()

        vdi, vdf, indices, this_mask = step_parameters.chooser(coor, single_molecule, pairdat, dtheta, number_of_ranges, reslow, numcont,
                                                               dihedral_parameters, beta, residue_rotation_indices, residue_rotation_mask, nonbondflag, first_last_resid, molecule_type, seed_object)

        angle = pairdat[0]
        residue_to_rotate = pairdat[1]
        theta = pairdat[2]

        # debugging

        #angle = 'psi'
        #residue_to_rotate = 5
        #theta = 5.0 * numpy.pi/180.0

        # end debugging

        # HARDWIRED
        if(residue_to_rotate < 7):
            this_group = groups[0]
            this_mask = group_masks[0]
            group_to_rotate = 0
        else:
            this_group = groups[1]
            this_mask = group_masks[1]
            group_to_rotate = 1

        group_rotation.rotate_a_group(
            this_group, rotate_type, residue_to_rotate, angle, theta, backward)
        check = check_ball_overlap(
            single_molecule, this_group, group_to_rotate, cutoff)

        if(check == 0):

            # debugging

            if(angle == 'psi'):

                basis = '(resid[i] == ' + str(residue_to_rotate) + ' and (name[i] == "N" or name[i] == "CA" or name[i] == "C")) or (resid[i] == ' + str(
                    residue_to_rotate + 1) + ' and (name[i] == "C") )'
                error, mask = single_molecule.get_subset_mask(basis)
                check_error(error)

                error, temp_coor = single_molecule.get_coor_using_mask(
                    frame, mask)
                check_error(error)
                lcoor = temp_coor[0]
                d_angle = sasmath.dihedral_angle(
                    lcoor[0], lcoor[1], lcoor[2], lcoor[3])
                print 'initial dihedral angle = ', d_angle
                da_outfile.write("%lf\n" % (d_angle))
                da_outfile.flush()

            # end debugging

            single_molecule.set_coor_using_mask(this_group, frame, this_mask)

            # debugging

            if(angle == 'psi'):
                error, temp_coor = single_molecule.get_coor_using_mask(
                    frame, mask)
                check_error(error)
                lcoor = temp_coor[0]
                d_angle = sasmath.dihedral_angle(
                    lcoor[0], lcoor[1], lcoor[2], lcoor[3])
                print 'final dihedral angle = ', d_angle

                port = 54321
                flag = 0
                single_molecule.send_coordinates_to_vmd(port, flag)

            # end debugging

            single_molecule.write_dcd_step(dcdoutfile, 0, taccepted + 1)
            taccepted += 1
        else:
            #			if(count == 10):
            #				print '.',
            #				dcdfile2 = dum_molecule.open_dcd_read('adum.dcd')
            #				nf=dcdfile2[2]
            #				my_frame = random.randint(0,nf)
            #				for j in xrange(my_frame):
            #					dum_molecule.read_dcd_step(dcdfile2,my_frame)
            #				dum_coor = dum_molecule.coor()[0]
            #				single_molecule.coor()[0] = dum_coor
            #				count = 0
            count += 1

        nsteps += 1

    return