Suggest domains for a protein structure

@param s the protein structure
@return a list of possible domains
@throws StructureException
547257
public static List<Domain> suggestDomains(Structure s) throws StructureException{

		Atom[] ca = StructureTools.getRepresentativeAtomArray(s);

		return suggestDomains(ca);
	}
874491
public void setDomainNames(java.util.Collection<String> domainNames) {
        if (domainNames == null) {
            this.domainNames = null;
            return;
        }

        this.domainNames = new java.util.ArrayList<String>(domainNames);
    }
402326
public void process() throws IOException, StructureException {
		if(sequences == null) { // only process once, then return cached values
			LinkedHashMap<String, ProteinSequence> sequenceMap = reader.process();

			sequences = sequenceMap.values().toArray(new ProteinSequence[0]);
			accessions = new String[sequences.length];
			structures = new Structure[sequences.length];
			residues = new ResidueNumber[sequences.length][];

			// Match each sequence  to a series of PDB Residue numbers
			for(int i=0;i<sequences.length;i++) {
				accessions[i] = sequences[i].getAccession().getID();

				//System.out.println("Fetching "+accession);
				structures[i] = cache.getStructure(accessions[i]);

				residues[i] = StructureSequenceMatcher.matchSequenceToStructure(sequences[i], structures[i]);

				assert( residues[i].length == sequences[i].getLength());
			}
		}
	}
1370654
public static StructureInterfaceList calculateInterfaces(Structure struc) {
		CrystalBuilder builder = new CrystalBuilder(struc);
		StructureInterfaceList interfaces = builder.getUniqueInterfaces();
		logger.debug("Calculating ASA for "+interfaces.size()+" potential interfaces");
		interfaces.calcAsas(StructureInterfaceList.DEFAULT_ASA_SPHERE_POINTS, //fewer for performance
				Runtime.getRuntime().availableProcessors(),
				StructureInterfaceList.DEFAULT_MIN_COFACTOR_SIZE);
		interfaces.removeInterfacesBelowArea();
		interfaces.getClusters();
		logger.debug("Found "+interfaces.size()+" interfaces");
		return interfaces;
	}
299915
public static final Atom[] getAllAtomArray(Structure s, int model) {
		List<Atom> atoms = new ArrayList<Atom>();

		AtomIterator iter = new AtomIterator(s,model);
		while (iter.hasNext()) {
			Atom a = iter.next();
			atoms.add(a);
		}
		return atoms.toArray(new Atom[atoms.size()]);

	}
1018656
public void align(Structure s1, String chainId1, Structure s2,
			String chainId2) throws StructureException {
		align(s1, chainId1, s2, chainId2, params);
	}
1277094
public Set<String> getIdsForTermWithAncestors(String s) {
        if (!indexByName.containsKey(s))
            return new HashSet<String>();
        Stack<String> idsToConsider = new Stack<String>();
        idsToConsider.addAll(getIdsForTerm(s));
        Set<String> resultIds = new HashSet<String>();
        while (!idsToConsider.isEmpty()) {
            String id = idsToConsider.pop();
            if (!resultIds.contains(id)) {
                resultIds.add(id);
                idsToConsider.addAll(terms.get(id).getIsA());
            }
        }
        return resultIds;
    }
1331510
public List<String> suggestTagNames(final String search,
      final int max_results) {
    return tag_names.suggest(search, max_results);
  }
69993
public Structure getStructureForDomain(String scopId, ScopDatabase scopDatabase) throws IOException,
			StructureException {
		ScopDomain domain = scopDatabase.getDomainByScopID(scopId);
		return getStructureForDomain(domain, scopDatabase);
	}
337307
public static List<SecStrucElement> getSecStrucElements(Structure s) {

		List<SecStrucElement> listSSE = new ArrayList<SecStrucElement>();
		GroupIterator iter = new GroupIterator(s);

		// SecStruc information - initialize
		SecStrucType type = SecStrucType.coil;
		ResidueNumber previous = new ResidueNumber();
		ResidueNumber start = new ResidueNumber();
		String chainId = "";
		int count = 0; // counts the number of residues in SSE

		// Create a map for the IDs of the SSE in the structure
		Map<SecStrucType, Integer> ids = new TreeMap<SecStrucType, Integer>();
		for (SecStrucType t : SecStrucType.values())
			ids.put(t, 1);

		while (iter.hasNext()) {
			Group g = iter.next();

			if (g.hasAminoAtoms()) {
				Object p = g.getProperty(Group.SEC_STRUC);
				if (p == null)
					continue;
				SecStrucInfo ss = (SecStrucInfo) p;

				if (count > 0) {
					// If chain and type are equal increment counter
					if (ss.type == type && chainId == g.getChainId()) {
						previous = g.getResidueNumber();
						count++;
						continue;
					} else {
						// Save the current SSE if chain or type change
						SecStrucElement sse = new SecStrucElement(type, start,
								previous, count, ids.get(type), chainId);
						listSSE.add(sse);
						ids.put(type, ids.get(type) + 1);
						count = 0;

						// Initialize a new SSE one
						if (ss.type != SecStrucType.coil) {
							type = ss.type;
							start = g.getResidueNumber();
							previous = start;
							chainId = g.getChainId();
							count = 1;
						}
					}
				} else {
					// This is for the first residue only
					if (ss.type != SecStrucType.coil) {
						type = ss.type;
						start = g.getResidueNumber();
						previous = start;
						chainId = g.getChainId();
						count = 1;
					}
				}
			}
		}
		return listSSE;
	}
270822
public static Atom[] getAtomCAArray(Structure s) {

		List<Atom> atoms = new ArrayList<Atom>();

		for (Chain c : s.getChains()) {
			for (Group g : c.getAtomGroups()) {
				if (g.hasAtom(CA_ATOM_NAME)
						&& g.getAtom(CA_ATOM_NAME).getElement() == Element.C) {
					atoms.add(g.getAtom(CA_ATOM_NAME));
				}
			}
		}

		return atoms.toArray(new Atom[atoms.size()]);
	}
937637
public static List<Target> from(final String srvName, final Iterable<String> domains) {
    final ImmutableList.Builder<Target> builder = ImmutableList.builder();
    for (final String domain : domains) {
      builder.add(new SrvTarget(srvName, domain));
    }
    return builder.build();
  }
501499
public static void showStructure(Structure structure)
			throws ClassNotFoundException, NoSuchMethodException,
			InvocationTargetException, IllegalAccessException, InstantiationException{

		Class<?> structureAlignmentJmol = Class.forName(strucAligJmol);

		Object strucAligJ = structureAlignmentJmol.newInstance();

		Method setS = structureAlignmentJmol.getMethod("setStructure", new Class[] {Structure.class});

		setS.invoke(strucAligJ,structure);
	}
841076
@Override
	public PDPDomain getPDPDomain(String pdpDomainName) throws IOException{
		SortedSet<String> domainRanges = null;
		if ( serializedCache != null){
			if ( serializedCache.containsKey(pdpDomainName)){
				domainRanges= serializedCache.get(pdpDomainName);

			}
		}


		boolean shouldRequestDomainRanges = checkDomainRanges(domainRanges);

		try {
			if (shouldRequestDomainRanges){
				URL u = new URL(server + "getPDPDomain?pdpId="+pdpDomainName);
				logger.info("Fetching {}",u);
				InputStream response = URLConnectionTools.getInputStream(u);
				String xml = JFatCatClient.convertStreamToString(response);
				domainRanges = XMLUtil.getDomainRangesFromXML(xml);
				if ( domainRanges != null)
					cache(pdpDomainName,domainRanges);
			}
		} catch (MalformedURLException e){
			logger.error("Problem generating PDP request URL for "+pdpDomainName,e);
			throw new IllegalArgumentException("Invalid PDP name: "+pdpDomainName, e);
		}

		String pdbId = null;
		List<ResidueRange> ranges = new ArrayList<ResidueRange>();
		for(String domainRange : domainRanges) {
			SubstructureIdentifier strucId = new SubstructureIdentifier(domainRange);
			if(pdbId == null) {
				pdbId = strucId.getPdbId();
			} else if(!pdbId.equals(strucId.getPdbId())) {
				// should never happen with correct server implementation
				throw new RuntimeException("Don't know how to take the union of domains from multiple PDB IDs.");
			}

			ranges.addAll(strucId.getResidueRanges());
		}
		return new PDPDomain(pdpDomainName,ranges);
	}
466755
public void setSubDomains(java.util.Collection<SubDomain> subDomains) {
        if (subDomains == null) {
            this.subDomains = null;
            return;
        }

        this.subDomains = new java.util.ArrayList<SubDomain>(subDomains);
    }
142830
public void align(Structure s1, String chainId1, Structure s2,
			String chainId2, StrucAligParameters params)
			throws StructureException {
		reset();
		this.params = params;

		Chain c1 = s1.getPolyChainByPDB(chainId1);
		Chain c2 = s2.getPolyChainByPDB(chainId2);

		Structure s3 = new StructureImpl();
		s3.addChain(c1);

		Structure s4 = new StructureImpl();
		s4.addChain(c2);

		Atom[] ca1 = getAlignmentAtoms(s3);
		Atom[] ca2 = getAlignmentAtoms(s4);

		notifyStartingAlignment(s1.getName(), ca1, s2.getName(), ca2);
		align(ca1, ca2, params);
	}
523417
public  PDPDistanceMatrix getDistanceMatrix(Atom[] protein) throws StructureException{
		int[][] dist = new int[protein.length+3][protein.length+3];
		int i,j;
		double d,dt1,dt2,dt3,dt4;
		int nclose=0;
		int[] iclose = new int[protein.length*protein.length];
		int[] jclose= new int[protein.length*protein.length];

		if(protein.length >= PDPParameters.MAXLEN) {
			System.err.println(String.format("%d protein.len > MAXLEN %d\n",protein.length,PDPParameters.MAXLEN));
			return null;
		}
		for(i=0;i<protein.length;i++) {
			for(j=i;j<protein.length;j++) {
				dist[i][j]=0;
				dist[j][i]=0;

				d=0;

				Atom ca1 = protein[i];
				Atom ca2 = protein[j];
				Group g1 = ca1.getGroup();
				Group g2 = ca2.getGroup();

				Atom cb1 = getCBeta(g1);
				Atom cb2 = getCBeta(g2);
				boolean hasCbeta1 = cb1 != null;
				boolean hasCbeta2 = cb2 != null;

				dt1=81;
				dt2=64;
				dt3=49;
				dt4=36;

				if(hasCbeta1 && hasCbeta2) {
					double distance = Calc.getDistance(cb1,cb2);
					d+= distance*distance;
				}
				else if(hasCbeta1 && ! hasCbeta2) {
					double distance = 999;

					distance = Calc.getDistance(cb1, ca2);
					d += distance * distance;
				}
				else if(!hasCbeta1&&hasCbeta2) {
					double distance = Calc.getDistance(ca1, cb2);
					d += distance * distance;
				}
				else if( ! hasCbeta1&&!hasCbeta2) {
					double distance = Calc.getDistance(ca1, ca2);
					d += distance * distance;
				}

				if(d<dt1) {
					dist[i][j]=1;
					dist[j][i]=1;
					if(d<dt2) {
						dist[i][j]=2;
						dist[j][i]=2;
						if(j-i>35) {
							iclose[nclose]=i;
							jclose[nclose]=j;
							nclose++;
						}
						if(d<dt3) {
							dist[i][j]=4;
							dist[j][i]=4;
							if(d<dt4) {
								dist[i][j]=6;
								dist[j][i]=6;
							}
						}
					}
				}
			}
		}
		/* secondary structure interaction */
		for(i=1;i<protein.length;i++) {
			for(j=i;j<protein.length-1;j++) {
				/* beta-sheet */
				if(dist[i][j]>=2&&j-i>5) {
					if(dist[i-1][j-1]>=2&&dist[i+1][j+1]>=2||dist[i-1][j+1]>=2&&dist[i+1][j-1]>=2) {
						dist[i][j]+=4;
						dist[j][i]+=4;
						/*
					printf("1: %d %d %d\n",i,j,dist[i][j]);
						 */
					}
					/* alpha-helices */
					else if(i>2&&j<protein.length-2) {
						if(dist[i-3][j-3]>=1&&dist[i+3][j+3]>=1||dist[i-3][j+3]>=1&&dist[i+3][j-3]>=1) {
							dist[i][j]+=4;
							dist[j][i]+=4;
							/*
						printf("3: %d %d %d\n",i,j,dist[i][j]);
							 */
						}
						else if(i>3&&j<protein.length-3) {
							if((dist[i-3][j-3]>=1||dist[i-3][j-4]>=1||dist[i-4][j-3]>=1||dist[i-4][j-4]>=1)&&
									(dist[i+4][j+4]>=1||dist[i+4][j+3]>=1||dist[i+3][j+3]>=1||dist[i+3][j+4]>=1)
									||(dist[i-4][j+4]>=1||dist[i-4][j+3]>=1||dist[i-3][j+4]>=1||dist[i-3][j+3]>=1)&&
									(dist[i+4][j-4]>=1||dist[i+4][j-3]>=1||dist[i+3][j-4]>=1||dist[i+3][j-3]>=1)) {
								dist[i][j]+=4;
								dist[j][i]+=4;
								/*
							printf("4: %d %d %d\n",i,j,dist[i][j]);
								 */
							}
						}
					}
				}
			}
		}

		PDPDistanceMatrix matrix = new PDPDistanceMatrix();

		matrix.setNclose(nclose);
		matrix.setIclose(iclose);
		matrix.setJclose(jclose);
		matrix.setDist(dist);
		return matrix;

	}