Quotient the chains to get equivalence classes of chains. These will be used for the actual mapping.
168160
def _determine_representative_chains(self):
        ''' '''
        # todo: This logic should be moved into the FASTA class or a more general module (maybe a fast exists which uses a C/C++ library?) but at present it is easier to write here since we do not need to worry about other PDB IDs.

        equivalence_fiber = {}
        matched_chains = set()
        for chain_id, equivalent_chains in self.identical_sequences.iteritems():
            matched_chains.add(chain_id)
            equivalent_chain_ids = set()
            for equivalent_chain in equivalent_chains:
                assert(len(equivalent_chain) == 6)
                assert((equivalent_chain[:5] == '%s_' % self.pdb_id) or (equivalent_chain[:5] == '%s:' % self.pdb_id)) # ClustalW changes e.g. 1KI1:A to 1KI1_A in its output
                equivalent_chain_ids.add(equivalent_chain[5])
            found = False
            for equivalent_chain_id in equivalent_chain_ids:
                if equivalence_fiber.get(equivalent_chain_id):
                    found = True
                    assert(equivalence_fiber[equivalent_chain_id] == equivalent_chain_ids.union(set([chain_id])))
                    break
            if not found:
                equivalence_fiber[chain_id] = set(equivalent_chain_ids)
                equivalence_fiber[chain_id].add(chain_id)

        for c in self.chains:
            if c not in matched_chains:
                equivalence_fiber[c] = set([c])

        self.equivalence_fiber = equivalence_fiber
        self.representative_chains = equivalence_fiber.keys()
94221
public static final void translate (Chain chain, Vector3d v) {

		for (Group g:chain.getAtomGroups()) {
			translate(g, v);
		}
	}
398825
def instances(cls):
        
        l = [i for i in cls.allinstances() if isinstance(i, cls)]
        return l
1279386
private Cardinalities getOrCreateCardinalities(Class<? extends ElementBase> sourceClass) {
        Cardinalities cardinalities = map.get(sourceClass);
        
        if (cardinalities == null) {
            map.put(sourceClass, cardinalities = new Cardinalities());
        }
        
        return cardinalities;
    }
88998
public static OClass getDeepestOClass(Iterable<OClass> classes) {
		if(classes==null) return null;
		OClass ret=null;
		for(OClass oClass: classes) {
			if(ret==null) ret = oClass;
			else {
				if(!ret.equals(oClass) && oClass.isSubClassOf(ret)) ret = oClass;
			}
		}
		return ret;
	}
1355828
def mapping(self):
        
        if not hasattr(self, "_mapping"):
            if hasattr(self.model, "Mapping"):
                mapping_klass = type("Mapping", (DjangoMapping, self.model.Mapping), {})
            else:
                mapping_klass = get_first_mapping(self.model)
                if mapping_klass is None:
                    mapping_klass = DjangoMapping
            self._mapping = mapping_klass(self.model)
        return self._mapping
533006
def map(self, coords):
        
        m = np.empty(coords.shape)
        m[:, :3] = (coords[:, :3] * self.scale[np.newaxis, :3] +
                    coords[:, 3:] * self.translate[np.newaxis, :3])
        m[:, 3] = coords[:, 3]
        return m
240090
def _build_inheritance_chain(cls, bases, *names, merge=False):
        """"""
        result = []
        for name in names:
            maps = []
            for base in bases:
                bmap = getattr(base, name, None)
                if bmap is not None:
                    assert isinstance(bmap, (dict, ChainMap))
                    if len(bmap):
                        if isinstance(bmap, ChainMap):
                            maps.extend(bmap.maps)
                        else:
                            maps.append(bmap)
            result.append(ChainMap({}, *maps))
        if merge:
            result = [dict(map) for map in result]
        if len(names) == 1:
            return result[0]
        return result
343755
public static List<EntityInfo> findPolyEntities(List<List<Chain>> polyModels) {
		TreeMap<String,EntityInfo> chainIds2entities = findEntitiesFromAlignment(polyModels);

		List<EntityInfo> entities = findUniqueEntities(chainIds2entities);

		return entities;
	}
1187517
public Set<ClassExpression> getGeneratorSubConcepts() {
		if (gens.size() == 1)
			return gens.iterator().next().getSubConcepts();
		
		Set<ClassExpression> all = new HashSet<ClassExpression>();		
		for (TreeWitnessGenerator twg : gens) 
			all.addAll(twg.getSubConcepts());
		return all;
	}
609892
def comparable(klass):
    
    # On Python 2, __cmp__ will just work, so no need to add extra methods:
    if not is_py3:
        return klass

    def __eq__(self, other):
        c = self.__cmp__(other)
        if c is NotImplemented:
            return c

        return c == 0

    def __ne__(self, other):
        c = self.__cmp__(other)
        if c is NotImplemented:
            return c

        return c != 0

    def __lt__(self, other):
        c = self.__cmp__(other)
        if c is NotImplemented:
            return c

        return c < 0

    def __le__(self, other):
        c = self.__cmp__(other)
        if c is NotImplemented:
            return c

        return c <= 0

    def __gt__(self, other):
        c = self.__cmp__(other)
        if c is NotImplemented:
            return c

        return c > 0

    def __ge__(self, other):
        c = self.__cmp__(other)
        if c is NotImplemented:
            return c

        return c >= 0

    klass.__lt__ = __lt__
    klass.__gt__ = __gt__
    klass.__le__ = __le__
    klass.__ge__ = __ge__
    klass.__eq__ = __eq__
    klass.__ne__ = __ne__
    return klass
650788
function getInheritanceChain() {
  return _(this.superClasses)
    .reverse()
    .reduce((acc, v) => v.getInheritanceChain().concat(acc), [this])
}
163925
Set<Class<?>> allClasses() {
        final Set<Class<?>> allClasses = new HashSet<>(getClasses());
        for (Object singleton : getSingletons()) {
            allClasses.add(singleton.getClass());
        }
        return allClasses;
    }
1276164
public int[] findTopoEquivClass(double[] weight) {
        int trialCount, i;
        int equivalentClass[] = new int[weight.length];
        int count = checkDiffNumber(weight);
        trialCount = count;
        if (count == nodeNumber) {
            for (i = 1; i <= nodeNumber; i++) {
                equivalentClass[i] = i;
            }
            equivalentClass[0] = count;
            return equivalentClass;
        }
        do {
            count = trialCount;
            double[][] trialNodeMatrix = buildTrialNodeMatrix(weight);
            double[] trialWeight = buildWeightMatrix(trialNodeMatrix, bondMatrix);
            trialCount = checkDiffNumber(trialWeight);
            if (trialCount == nodeNumber) {
                for (i = 1; i <= nodeNumber; i++) {
                    equivalentClass[i] = i;
                }
                equivalentClass[0] = count;
                return equivalentClass;
            }
            if (trialCount <= count) {
                equivalentClass = getEquivalentClass(weight);
                return equivalentClass;
            }
        } while (trialCount > count);
        return equivalentClass;
    }
1236871
public int[] getEquivalentClass(double[] weight) {
        double category[] = new double[weight.length];
        int equivalentClass[] = new int[weight.length];
        int i, j;
        int count = 1;
        double t;
        category[1] = weight[1];
        for (i = 2; i < weight.length; i++) {
            for (j = 1; j <= count; j++) {
                t = weight[i] - category[j];
                if (t < 0.0) {
                    t = -t;
                }
                if (t < LOST) {
                    break;
                }
            }
            if (j > count) {
                count += 1;
                category[count] = weight[i];
            }
        }

        for (i = 1; i < weight.length; i++) {
            for (j = 1; j <= count; j++) {
                t = weight[i] - category[j];
                if (t < 0.0) {
                    t = -t;
                }
                if (t < LOST) {
                    equivalentClass[i] = j;
                }
            }
        }
        equivalentClass[0] = count;
        return equivalentClass;
    }
522329
def _subclassed(base, *classes):
        
        return all(map(lambda obj: isinstance(obj, base), classes))
1156391
public Set<String> getChains() {
		Set<String> chains = new HashSet<String>();
		List<ResidueRange> rrs = toCanonical().getResidueRanges();
		for (ResidueRange rr : rrs) chains.add(rr.getChainName());
		return chains;
	}

	@Override
	public String getIdentifier() {
		return getCATH();
	}

	@Override
	public SubstructureIdentifier toCanonical() {
		List<ResidueRange> ranges = new ArrayList<ResidueRange>();
		String chain = String.valueOf(getDomainName().charAt(getDomainName().length() - 3));
		for (CathSegment segment : this.getSegments()) {
			ranges.add(new ResidueRange(chain, segment.getStart(), segment.getStop()));
		}

		return new SubstructureIdentifier(getThePdbId(), ranges);
	}

	@Override
	public Structure reduce(Structure input) throws StructureException {
		return toCanonical().reduce(input);
	}

	@Override
	public Structure loadStructure(AtomCache cache) throws StructureException,
			IOException {
		return cache.getStructure(getThePdbId());
	}


}