def fit_by_ndx(ref, model, ndx1, ndx2): crd1 = map(lambda i: ref.atoms[i-1].x, ndx1) crd2 = map(lambda i: model.atoms[i-1].x, ndx2) assert( len(crd1) == len(crd2) ) m = map(lambda x: 1., crd1) # dummy array v = _p.center_vec( crd1 ) v2 = _p.center_vec( crd2 ) R = _p.calc_fit_R(crd1, crd2, m) model.translate( [-v2[0], -v2[1], -v2[2] ] ) apply_fit_R( model.atoms, R) model.translate( v )
def fit_atoms( fit_atoms1, fit_atoms2, rot_atoms2 ): cs1 = map(lambda a: a.x, fit_atoms1) cs2 = map(lambda a: a.x, fit_atoms2) assert len(cs1) == len(cs2) m = map(lambda x: 1., cs1) # dummy array v = _p.center_vec( cs1 ) v2 = _p.center_vec( cs2 ) R = _p.calc_fit_R(cs1, cs2, m) for atom in rot_atoms2: atom.x[0]-=v2[0] atom.x[1]-=v2[1] atom.x[2]-=v2[2] apply_fit_R( rot_atoms2, R) for atom in rot_atoms2: atom.x[0]+=v[0] atom.x[1]+=v[1] atom.x[2]+=v[2]
def fit(model1, model2, atom_names = []): if atom_names: subset1 = model1.fetch_atoms( atom_names ) subset2 = model2.fetch_atoms( atom_names ) cs1 = map(lambda a: a.x, subset1) cs2 = map(lambda a: a.x, subset2) else: cs1 = model1.coords() cs2 = model2.coords() assert( len(cs1) == len(cs2) ) m = map(lambda x: 1., cs1) # dummy array v = _p.center_vec( cs1 ) v2 = _p.center_vec( cs2 ) R = _p.calc_fit_R(cs1, cs2, m) model2.translate( [-v2[0], -v2[1], -v2[2] ] ) apply_fit_R( model2.atoms, R) model2.translate( v )
def calc_fit_R(cs1, cs2, m): R = _p.calc_fit_R(cs1, cs2, m) return (R)