/** * Finds in the given list of chains the first one that has as name the given chainID. * If no such Chain can be found it returns null. */ private static Chain isKnownChain(String chainID, List<Chain> chains){ for (int i = 0; i< chains.size();i++){ Chain testchain = chains.get(i); if (chainID.equals(testchain.getName())) { return testchain; } } return null; }
/** * {@inheritDoc} */ @Override public void setChain(Chain chain) { this.parent = chain; //TODO: setChain(), getChainName() and ResidueNumber.set/getChainName() are //duplicating functionality at present and could give different values. if (residueNumber != null) { residueNumber.setChainName(chain.getName()); } }
@Override public Chain getWaterChainByPDB(String authId, int modelIdx) { Model model = models.get(modelIdx); if (model==null) { return null; } List<Chain> waterChains = model.getWaterChains(); for (Chain c : waterChains){ if (c.getName().equals(authId)) return c; } return null; }
@Override public Chain getPolyChainByPDB(String authId, int modelIdx) { Model model = models.get(modelIdx); if (model==null) { return null; } List<Chain> polyChains = model.getPolyChains(); for (Chain c : polyChains){ if (c.getName().equals(authId)) return c; } return null; }
/** {@inheritDoc} */ @Override public boolean hasPdbChain(String authId) { int modelnr = 0; List<Chain> chains = getChains(modelnr); for (Chain c : chains) { // we check here with equals because we might want to distinguish between upper and lower case chains! if (c.getName().equals(authId)) { return true; } } return false; }
/** * Gets all chains with given chainName from given models list * @param chainName * @param polyModels * @return */ private static List<List<Chain>> findChains(String chainName, List<List<Chain>> polyModels) { List<List<Chain>> models = new ArrayList<>(); for (List<Chain> chains:polyModels) { List<Chain> matchingChains = new ArrayList<>(); models.add(matchingChains); for (Chain c:chains) { if (c.getName().equals(chainName)) { matchingChains.add(c); } } } return models; }
@Override public List<Chain> getNonPolyChainsByPDB(String authId, int modelIdx) { List<Chain> chains = new ArrayList<>(); Model model = models.get(modelIdx); if (model==null) { return chains; } List<Chain> nonpolyChains = model.getNonPolyChains(); for (Chain c : nonpolyChains){ if (c.getName().equals(authId)) chains.add(c); } return chains; }
public static String toMMCIF(Chain chain, boolean writeHeader) { StringBuilder sb = new StringBuilder(); sb.append(SimpleMMcifParser.MMCIF_TOP_HEADER+"BioJava_mmCIF_file"+newline); sb.append(toMMCIF(chain, chain.getName(), chain.getId(),writeHeader)); return sb.toString(); }
/** * * @param seqRes * @param atomList * @param useChainId if true chainId (Chain.getId) is used for matching, * if false chainName (Chain.getName) is used * @return */ public static Chain getMatchingAtomRes(Chain seqRes, List<Chain> atomList, boolean useChainId) { Iterator<Chain> iter = atomList.iterator(); while(iter.hasNext()){ Chain atomChain = iter.next(); String atomChainId = null; String seqResChainId = null; if (useChainId) { atomChainId = atomChain.getId(); seqResChainId = seqRes.getId(); } else { atomChainId = atomChain.getName(); seqResChainId = seqRes.getName(); } if ( atomChainId.equals(seqResChainId)){ return atomChain; } } logger.info("Could not match SEQRES chainID asymId:" + seqRes.getId() + " authId:"+ seqRes.getName() +" to ATOM chains!, size of atom chain: " + atomList.size()); return null; }
/** * Converts a Structure into a List of {@link AtomSite} objects * @param s * @return */ public static List<AtomSite> convertStructureToAtomSites(Structure s) { List<AtomSite> list = new ArrayList<AtomSite>(); for (int m=0;m<s.nrModels();m++) { for (Chain c:s.getChains(m)) { list.addAll(convertChainToAtomSites(c, m+1, c.getName(), c.getId())); } } return list; }
public void addChain(Chain c) { EntityInfo info = c.getEntityInfo(); if ( info == null || info.getType() == null) { logger.info("No entity info could be found while adding chain with asym id {} (author id {}). Will consider it a polymer chain.", c.getId(), c.getName()); polyChains.add(c); } else if ( info.getType() == EntityType.POLYMER) { polyChains.add(c); } else if (info.getType() == EntityType.NONPOLYMER) { nonPolyChains.add(c); } else if (info.getType() == EntityType.WATER) { waterChains.add(c); } else if (info.getType() == EntityType.MACROLIDE) { logger.warn("Chain with asym id {} (author id {}) has entity type 'macrolide', considering it non-polymeric", c.getId(), c.getName()); nonPolyChains.add(c); } else { logger.warn("Chain with asym id {} (author id {}) has unsupported entity type '{}'. Will not add it to the Structure.", c.getId(), c.getName(), info.getType().toString()); // ignore it } }
/** * Converts a Chain into a List of {@link AtomSite} objects * @param c the chain * @param model the model number for the output AtomSites * @param chainName the chain identifier (author id) for the output AtomSites * @param chainId the internal chain identifier (asym id) for the output AtomSites * @return */ public static List<AtomSite> convertChainToAtomSites(Chain c, int model, String chainName, String chainId) { List<AtomSite> list = new ArrayList<>(); if (c.getEntityInfo()==null) { logger.warn("No Compound (entity) found for chain {}: entity_id will be set to 0, label_seq_id will be the same as auth_seq_id", c.getName()); } for ( int h=0; h<c.getAtomLength();h++){ Group g= c.getAtomGroup(h); list.addAll(convertGroupToAtomSites(g, model, chainName, chainId)); } return list; }
private StructureInterface calcContacts(Chain chaini, Chain chainj, double cutoff, CrystalTransform tt, StringBuilder builder) { // note that we don't consider hydrogens when calculating contacts AtomContactSet graph = StructureTools.getAtomsInContact(chaini, chainj, cutoff, INCLUDE_HETATOMS); if (graph.size()>0) { if (builder != null) builder.append("x"); CrystalTransform transf = new CrystalTransform(this.crystallographicInfo.getSpaceGroup()); StructureInterface interf = new StructureInterface( StructureTools.getAllAtomArray(chaini), StructureTools.getAllAtomArray(chainj), chaini.getName(), chainj.getName(), graph, transf, tt); return interf; } else { if (builder != null) builder.append("o"); return null; } }
public static void toPDB(Atom a, StringBuffer str) { toPDB(a,str,a.getGroup().getChain().getName()); }
private static CharSequence getPDBPos(Atom atom) { Group g = atom.getGroup(); if ( g!= null){ Chain c = g.getChain(); if (c != null){ return g.getResidueNumber().toString()+":" + c.getName() ; //return g.getPDBCode()+":" + c.getName() + "." + getOneLetter(g) ; } } return "!"; }
/** get the position of PDB residue nr X in the ato marray * * @param pdbresnum pdbresidue number * @param authId chain name * @param atoms atom array * @return */ private static int getPositionForPDBresunm(String pdbresnum, String authId , Atom[] atoms){ ResidueNumber residueNumber = ResidueNumber.fromString(pdbresnum); residueNumber.setChainName(authId); boolean blankChain = authId == null || authId.equalsIgnoreCase("null") || authId.equals("_"); for ( int i =0; i< atoms.length ;i++){ Group g = atoms[i].getGroup(); // match _ to any chain if( blankChain ) { residueNumber.setChainName(g.getChain().getName()); } //System.out.println(g.getResidueNumber() + "< ? >" + residueNumber +"<"); if ( g.getResidueNumber().equals(residueNumber)){ //System.out.println(g + " == " + residueNumber ); Chain c = g.getChain(); if ( blankChain || c.getName().equals(authId)){ return i; } } } return -1; }
/** * Adds a chain to the given structure to form a biological assembly, * adding the symmetry-expanded chains as new chains with renamed * chain ids and names (in the form originalAsymId_transformId and originalAuthId_transformId). * @param s * @param newChain * @param transformId */ private void addChainFlattened(Structure s, Chain newChain, String transformId) { newChain.setId(newChain.getId()+"_"+transformId); newChain.setName(newChain.getName()+"_"+transformId); s.addChain(newChain); }
public static void printXMLEQRInferPositions(PrettyXMLWriter xml, AFPChain afpChain, int bk, Atom[] ca1, Atom[] ca2) throws IOException{ int[] optLen = afpChain.getOptLen(); if ( optLen == null) return; int[][][] optAln = afpChain.getOptAln(); for ( int pos=0;pos< optLen[bk];pos++){ int pos1 = optAln[bk][0][pos]; int pos2 = optAln[bk][1][pos]; xml.openTag("eqr"); xml.attribute("eqrNr", String.valueOf(pos)); xml.attribute("pdbres1",ca1[pos1].getGroup().getResidueNumber().toString()); xml.attribute("chain1", ca1[pos1].getGroup().getChain().getName()); xml.attribute("pdbres2",ca2[pos2].getGroup().getResidueNumber().toString()); xml.attribute("chain2", ca2[pos2].getGroup().getChain().getName()); xml.closeTag("eqr"); //System.out.println("aligned position: " + pos1 + ":" + pos2 + //" pdbresnum " + ca1[pos1].getGroup().getResidueNumber().toString() + " " + //ca1[pos1].getParent().getPDBName()+":" + //ca2[pos2].getGroup().getResidueNumber().toString() + " " + ca2[pos2].getParent().getPDBName()); } }
newChain.setName(chain.getName()); newChain.setEntityInfo(chain.getEntityInfo()); newChain.setSwissprotId(chain.getSwissprotId());