code: public static Structure getSubstructureMatchingProteinSequence(ProteinSequence sequence, Structure wholeStructure) {
  		ResidueNumber[] rns = matchSequenceToStructure(sequence, wholeStructure);
  		Structure structure = wholeStructure.clone();
  		structure.setChains(new ArrayList<>());
  //		structure.getHetGroups().clear();
  		Chain currentChain = null;
  		for (ResidueNumber rn : rns) {
  			if (rn == null) continue;
  			Group group; // note that we don't clone
  			try {
  				group = StructureTools.getGroupByPDBResidueNumber(wholeStructure, rn);
  			} catch (StructureException e) {
  				throw new IllegalArgumentException("Could not find residue " + rn + " in structure", e);
  			}
  			Chain chain = new ChainImpl();
  			chain.setName(group.getChain().getName());
  			chain.setId(group.getChain().getId());
  			if (currentChain == null || !currentChain.getId().equals(chain.getId())) {
  				structure.addChain(chain);
  				chain.setEntityInfo(group.getChain().getEntityInfo());
  				chain.setStructure(structure);
  				chain.setSwissprotId(group.getChain().getSwissprotId());
  				chain.setId(group.getChain().getId());
  				chain.setName(group.getChain().getName());
  				currentChain = chain;
  			}
  			currentChain.addGroup(group);
  		}
  		return structure;
  	}
docs: Get a substructure of {@code wholeStructure} containing only the {@link Group Groups} that are included in
  {@code sequence}. The resulting structure will contain only {@code ATOM} residues; the SEQ-RES will be empty.
  The {@link Chain Chains} of the Structure will be new instances (cloned), but the {@link Group Groups} will not.
  @param sequence The input protein sequence
  @param wholeStructure The structure from which to take a substructure
  @return The resulting structure
  @throws StructureException
  @see {@link #matchSequenceToStructure(ProteinSequence, Structure)}