def rotateCoordinates(coords, rotations, center):
    from moleculekit.util import rotationMatrix

    def rotate(coords, rotMat, center=(0, 0, 0)):
        newcoords = coords - center
        return np.dot(newcoords, np.transpose(rotMat)) + center

    rotation = list(rotations)
    matx = rotationMatrix([1, 0, 0], rotation[0])
    maty = rotationMatrix([0, 1, 0], rotation[1])
    matz = rotationMatrix([0, 0, 1], rotation[2])

    coords = coords.copy()
    coords = rotate(coords, matx, center=center)
    coords = rotate(coords, maty, center=center)
    coords = rotate(coords, matz, center=center)
    return coords
Esempio n. 2
0
def moveLipidToPos(mol, lip):
    from moleculekit.util import rotationMatrix
    mol = mol.copy()
    headpos = mol.coords[mol.name == lip.headname].flatten()[np.newaxis, :]
    mol.moveBy(-headpos)
    mol.rotateBy(rotationMatrix([0, 0, 1], np.deg2rad(lip.rot)))
    mol.moveBy(lip.xyz)
    return np.squeeze(mol.coords[:, :, 0])
Esempio n. 3
0
    def test_align(self):
        from moleculekit.util import rotationMatrix
        import numpy as np

        sm = SmallMol(self.benzamidine_mol2)
        mol = sm.toMolecule()
        mol.rotateBy(rotationMatrix([1, 0, 0], 3.14))
        sm.align(mol)
        
        assert (np.abs(sm._coords) - np.abs(mol.coords)).max()  # I need to do the abs of the coords since it's a symmetrical molecule
Esempio n. 4
0
def _loadMolecules(lipids, files):
    from moleculekit.util import rotationMatrix
    # Create Molecules
    for l in lipids:
        randidx = np.random.randint(len(files[l.resname]))
        mol = Molecule(files[l.resname][randidx])
        mol.filter('not water', _logger=False)
        if l.xyz[2] < 0:
            mol.rotateBy(rotationMatrix([1, 0, 0], np.deg2rad(180)))  # Rotate the lower leaflet lipids upside down
        l.mol = mol
        l.rot = np.random.random() * 360 - 180  # Random starting rotation
def _totalContacts(x, *args):
    from moleculekit.util import rotationMatrix

    lipids = args[0]
    headnames = args[1]
    zpos = args[2]
    thresh = args[3]
    neighbours = args[4]
    numlips = args[5]
    box = args[6]
    newxy = np.array(x[:numlips * 2]).reshape((-1, 2))
    rots = x[numlips * 2:]

    allcoords = []
    for i in range(numlips):
        cc = np.squeeze(lipids[i].mol.coords)
        headpos = cc[lipids[i].mol.name == headnames[i]].flatten()[
            np.newaxis, :]
        cc = cc - headpos  # Center it on the head position
        newloc = np.hstack(
            (newxy[i], zpos[i]))[np.newaxis, :]  # Calculate new head position

        # Doing the rotation
        M = rotationMatrix([0, 0, 1], np.deg2rad(rots[i]))
        newcoords = np.dot(cc, np.transpose(M))

        allcoords.append(newcoords + newloc)

    allcoords = np.array(allcoords, dtype=object)
    numcontacts = 0
    for i in range(len(allcoords)):
        if len(neighbours[i]) == 0:
            continue
        neighcoor = np.vstack(allcoords[neighbours[i]])
        dists = _wrapping_dist(allcoords[i], neighcoor,
                               np.array(box, dtype=float))
        numcontacts += np.count_nonzero(dists < thresh)

    return numcontacts
Esempio n. 6
0
def _createMembraneMolecule(lipids):
    from moleculekit.util import rotationMatrix

    allmols = []
    for i, l in enumerate(lipids):
        mol = l.mol.copy()
        headpos = mol.coords[mol.name == l.headname].flatten()[np.newaxis, :]
        mol.moveBy(-headpos)
        mol.rotateBy(rotationMatrix([0, 0, 1], np.deg2rad(l.rot)))
        mol.moveBy(l.xyz)
        mol.resid[:] = i
        allmols.append(mol)
    
    def mergeMols(mollist):  # Divide and conquer approach for merging molecules
        while len(mollist) > 1:
            mollist[0].append(mollist[1])
            mollist = [mollist[0]] + mergeMols(mollist[2:])
        if len(mollist) == 1:
            return mollist
        return []

    return mergeMols(allmols)[0]