def moveLipidToPos(mol, lip): from htmd.rotationmatrix 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])
def _loadMolecules(lipids, files): from htmd.rotationmatrix 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 _loadMolecules(lipids, files): from htmd.rotationmatrix 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 htmd.rotationmatrix 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 = np.zeros((allcoords[i].shape[0], neighcoor.shape[0])) wrapping_dist_numba(allcoords[i], neighcoor, dists, np.array(box, dtype=float)) numcontacts += np.count_nonzero(dists < thresh) return numcontacts
def _createMembraneMolecule(lipids): from htmd.rotationmatrix 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]
def _createMembraneMolecule(lipids): from htmd.rotationmatrix 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]
def totalContacts(x, *args): from htmd.rotationmatrix 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 = np.zeros((allcoords[i].shape[0], neighcoor.shape[0])) wrapping_dist_numba(allcoords[i], neighcoor, dists, np.array(box, dtype=float)) numcontacts += np.count_nonzero(dists < thresh) return numcontacts