def _loadMols(self, i, rel, molfile, wrapsel, alignsel, refmol): frames = self.data.rel2sim(rel) mol = Molecule(molfile) trajs = np.empty(0, dtype=str) frs = np.empty(0, dtype=int) for f in frames: trajs = np.append(trajs, f.sim.trajectory[f.piece]) frs = np.append(frs, f.frame) mol.read(trajs, frames=frs) if len(wrapsel) > 0: mol.wrap(wrapsel) if refmol is not None: mol.align(alignsel, refmol=refmol) return mol
def _loadMols(self, rel, molfile, wrapsel, alignsel, refmol, simlist): frames = self.data.rel2sim(rel, simlist=simlist) mol = Molecule(molfile) trajs = np.empty(0, dtype=str) frs = np.empty(0, dtype=int) for f in frames: trajs = np.append(trajs, f.sim.trajectory[f.piece]) frs = np.append(frs, f.frame) mol.read(trajs, frames=frs) if len(wrapsel) > 0: mol.wrap(wrapsel) if (refmol is not None) and (alignsel is not None): mol.align(alignsel, refmol=refmol) return mol
def viewStates(self, protein=None, ligand=None, nsamples=20): from htmd.projections.metric import _singleMolfile from htmd.molecule.molecule import Molecule from htmd.vmdviewer import getCurrentViewer (single, molfile) = _singleMolfile(self.data.simlist) if not single: raise RuntimeError('Can' 't visualize states without unique molfile') viewer = getCurrentViewer() colors = [0, 1, 3, 4, 5, 6, 7, 9] print('Active set includes macrostates: {}'.format( self.hmm.active_set)) # dtraj = np.vstack(self.hmm.discrete_trajectories_full) res = self.hmm.sample_by_observation_probabilities(nsamples) refmol = Molecule(molfile) for i, s in enumerate(self.hmm.active_set): mol = Molecule(molfile) mol.coords = [] mol.box = [] # idx = np.where(dtraj == i)[0] # samples = np.random.choice(idx, 20) # frames = self.data.abs2sim(samples) frames = self.data.rel2sim(res[i]) for f in frames: mol._readTraj(f.sim.trajectory[f.piece], frames=[f.frame], append=True) mol.wrap('protein') mol.align('protein', refmol=refmol) viewer.loadMol(mol, name='hmm macro ' + str(s)) if ligand is not None: viewer.rep('ligand', sel=ligand, color=colors[np.mod(i, len(colors))]) if protein is not None: viewer.rep('protein') viewer.send('start_sscache')
def viewStates(self, protein=None, ligand=None, nsamples=20): from htmd.projections.metric import _singleMolfile from htmd.molecule.molecule import Molecule from htmd.vmdviewer import getCurrentViewer (single, molfile) = _singleMolfile(self.data.simlist) if not single: raise RuntimeError('Can''t visualize states without unique molfile') viewer = getCurrentViewer() colors = [0, 1, 3, 4, 5, 6, 7, 9] print('Active set includes macrostates: {}'.format(self.hmm.active_set)) # dtraj = np.vstack(self.hmm.discrete_trajectories_full) res = self.hmm.sample_by_observation_probabilities(nsamples) refmol = Molecule(molfile) for i, s in enumerate(self.hmm.active_set): mol = Molecule(molfile) mol.coords = [] mol.box = [] # idx = np.where(dtraj == i)[0] # samples = np.random.choice(idx, 20) # frames = self.data.abs2sim(samples) frames = self.data.rel2sim(res[i]) for f in frames: mol._readTraj(f.sim.trajectory[f.piece], frames=[f.frame], append=True) mol.wrap('protein') mol.align('protein', refmol=refmol) viewer.loadMol(mol, name='hmm macro ' + str(s)) if ligand is not None: viewer.rep('ligand', sel=ligand, color=colors[np.mod(i, len(colors))]) if protein is not None: viewer.rep('protein') viewer.send('start_sscache')
Ra=226.00, Ac=227.00, Th=232.04, Pa=231.04, U=238.03, Np=237.00, Pu=244.00, Am=243.00, Cm=247.00, Bk=247.00, Cf=251.00, Es=252.00, Fm=257.00, Md=258.00, No=259.00, Lr=262.00, Rf=261.00, Db=262.00, Sg=266.00, Bh=264.00, Hs=269.00, Mt=268.00) mol = mol.copy() mol.filter(sel, _logger=False) mol.wrap("protein") mol.center() mass = np.array([_atomic_mass[i] for i in mol.element]) t_mass = np.sum(mass) center_of_mass = np.sum(mol.coords * mass[:, None, None], axis=0) / t_mass dist_from_com = np.sqrt(np.sum((mol.coords - center_of_mass)**2, axis=1)) rg = np.sqrt(np.sum(mass[: , None] * dist_from_com**2, axis=0) / t_mass) return rg[:, None] if __name__ == '__main__': from htmd.molecule.molecule import Molecule # from htmd.projections.metric import Metric # met_rg = Metric(sim) mol = Molecule("./ref_files/MD_trajectory/structure.pdb") mol.read("./ref_files/MD_trajectory/structure.psf") mol.read("./ref_files/MD_trajectory/output.xtc") mol.wrap("protein") mol.align("protein") met = metricRG(mol)