529 """ Same as :func:`Score` but with flat mapping
531 :param flat_mapping: Dictionary with target chain names as keys and
532 the mapped model chain names as value
533 :type flat_mapping: :class:`dict` with :class:`str` as key and value
534 :returns: Result object of type :class:`QSScorerResult`
537 weighted_scores = 0.0
539 weight_extra_mapped = 0.0
540 weight_extra_all = 0.0
543 processed_qsent2_interfaces = set()
546 if int1[0]
in flat_mapping
and int1[1]
in flat_mapping:
547 int2 = (flat_mapping[int1[0]], flat_mapping[int1[1]])
551 weight_extra_mapped += c
552 weight_extra_all += d
553 processed_qsent2_interfaces.add((min(int2[0], int2[1]),
554 max(int2[0], int2[1])))
559 r_flat_mapping = {v:k
for k,v
in flat_mapping.items()}
561 if int2
not in processed_qsent2_interfaces:
562 if int2[0]
in r_flat_mapping
and int2[1]
in r_flat_mapping:
563 int1 = (r_flat_mapping[int2[0]], r_flat_mapping[int2[1]])
567 weight_extra_mapped += c
568 weight_extra_all += d
574 mapped_trg_chains = sorted(flat_mapping.keys())
575 mapped_mdl_chains = sorted(flat_mapping.values())
576 trg_complete = trg_chains == mapped_trg_chains
577 mdl_complete = mdl_chains == mapped_mdl_chains
578 complete_mapping = trg_complete
and mdl_complete
580 return QSScorerResult(weighted_scores, weight_sum, weight_extra_mapped,
581 weight_extra_all, complete_mapping)
604 if int1[0] > int1[1]:
606 if int2[0] > int2[1]:
610 mapped_indices_1_1, mapped_indices_1_2 = \
613 mapped_indices_2_1, mapped_indices_2_2 = \
621 mapped_idx_grid_1 = np.ix_(mapped_indices_1_1, mapped_indices_2_1)
622 mapped_idx_grid_2 = np.ix_(mapped_indices_1_2, mapped_indices_2_2)
624 if mapped_indices_1_1.shape[0] == 0
or mapped_indices_2_1.shape[0] == 0:
629 shared_mask_d1 = np.full(d1.shape,
False, dtype=bool)
630 shared_mask_d2 = np.full(d2.shape,
False, dtype=bool)
631 mapped_nonshared_mask_d1 = np.full(d1.shape,
False, dtype=bool)
632 mapped_nonshared_mask_d2 = np.full(d2.shape,
False, dtype=bool)
633 if mapped_indices_1_1.shape[0] == 0
or \
634 mapped_indices_2_1.shape[0] == 0:
637 mapped_d1_contacts = np.full(d1.shape,
False, dtype=bool)
639 mapped_d1_contacts = d1[mapped_idx_grid_1] < contact_d
640 mapped_nonshared_mask_d1[mapped_idx_grid_1] = mapped_d1_contacts
642 if mapped_indices_1_2.shape[0] == 0
or \
643 mapped_indices_2_2.shape[0] == 0:
646 mapped_d2_contacts = np.full(d2.shape,
False, dtype=bool)
648 mapped_d2_contacts = d2[mapped_idx_grid_2] < contact_d
649 mapped_nonshared_mask_d2[mapped_idx_grid_2] = mapped_d2_contacts
650 shared_mask = np.full(mapped_d1_contacts.shape,
False, dtype=bool)
652 mapped_d1_contacts = d1[mapped_idx_grid_1] < contact_d
653 mapped_d2_contacts = d2[mapped_idx_grid_2] < contact_d
654 shared_mask = np.logical_and(mapped_d1_contacts, mapped_d2_contacts)
655 shared_mask_d1 = np.full(d1.shape,
False, dtype=bool)
656 shared_mask_d1[mapped_idx_grid_1] = shared_mask
657 shared_mask_d2 = np.full(d2.shape,
False, dtype=bool)
658 shared_mask_d2[mapped_idx_grid_2] = shared_mask
661 mapped_nonshared_mask_d1 = np.full(d1.shape,
False, dtype=bool)
662 mapped_nonshared_mask_d1[mapped_idx_grid_1] = \
663 np.logical_and(np.logical_not(shared_mask), mapped_d1_contacts)
664 mapped_nonshared_mask_d2 = np.full(d2.shape,
False, dtype=bool)
665 mapped_nonshared_mask_d2[mapped_idx_grid_2] = \
666 np.logical_and(np.logical_not(shared_mask), mapped_d2_contacts)
669 shared_d1 = d1[shared_mask_d1]
670 shared_d2 = d2[shared_mask_d2]
671 shared_min = np.minimum(shared_d1, shared_d2)
672 shared_abs_diff_div_12 = np.abs(np.subtract(shared_d1, shared_d2))/12.0
673 weight_term = np.ones(shared_min.shape[0])
674 bigger_5_mask = shared_min > 5.0
675 weights = np.exp(-2.0*np.square((shared_min[bigger_5_mask]-5.0)/4.28))
676 weight_term[bigger_5_mask] = weights
677 diff_term = np.subtract(np.ones(weight_term.shape[0]),
678 shared_abs_diff_div_12)
679 weighted_scores = np.sum(np.multiply(weight_term, diff_term))
680 weight_sum = np.sum(weight_term)
683 nonshared_contact_mask_d1 = np.logical_and(np.logical_not(shared_mask_d1),
685 contact_distances = d1[nonshared_contact_mask_d1]
686 bigger_5 = contact_distances[contact_distances > 5]
687 weight_extra_all = np.sum(np.exp(-2.0*np.square((bigger_5-5.0)/4.28)))
689 weight_extra_all += contact_distances.shape[0] - bigger_5.shape[0]
691 nonshared_contact_mask_d2 = np.logical_and(np.logical_not(shared_mask_d2),
693 contact_distances = d2[nonshared_contact_mask_d2]
694 bigger_5 = contact_distances[contact_distances > 5]
695 weight_extra_all += np.sum(np.exp(-2.0*np.square((bigger_5-5.0)/4.28)))
697 weight_extra_all += contact_distances.shape[0] - bigger_5.shape[0]
700 contact_distances = d1[mapped_nonshared_mask_d1]
701 bigger_5 = contact_distances[contact_distances > 5]
702 weight_extra_mapped = np.sum(np.exp(-2.0*np.square((bigger_5-5.0)/4.28)))
704 weight_extra_mapped += contact_distances.shape[0] - bigger_5.shape[0]
706 contact_distances = d2[mapped_nonshared_mask_d2]
707 bigger_5 = contact_distances[contact_distances > 5]
708 weight_extra_mapped += np.sum(np.exp(-2.0*np.square((bigger_5-5.0)/4.28)))
710 weight_extra_mapped += contact_distances.shape[0] - bigger_5.shape[0]
712 return (weighted_scores, weight_sum, weight_extra_mapped, weight_extra_all)