Java Code Examples for org.biojava.nbio.structure.Structure#nrModels()
The following examples show how to use
org.biojava.nbio.structure.Structure#nrModels() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BiologicalAssemblyBuilder.java From biojava with GNU Lesser General Public License v2.1 | 6 votes |
/** * Adds a chain to the given structure to form a biological assembly, * adding the symmetry expanded chains as new models per transformId. * @param s * @param newChain * @param transformId */ private void addChainMultiModel(Structure s, Chain newChain, String transformId) { // multi-model bioassembly if ( modelIndex.size() == 0) modelIndex.add("PLACEHOLDER FOR ASYM UNIT"); int modelCount = modelIndex.indexOf(transformId); if ( modelCount == -1) { modelIndex.add(transformId); modelCount = modelIndex.indexOf(transformId); } if (modelCount == 0) { s.addChain(newChain); } else if (modelCount > s.nrModels()) { List<Chain> newModel = new ArrayList<>(); newModel.add(newChain); s.addModel(newModel); } else { s.addChain(newChain, modelCount-1); } }
Example 2
Source File: SymmetryTools.java From biojava with GNU Lesser General Public License v2.1 | 6 votes |
/** * Returns the representative Atom Array of the first model, if the * structure is NMR, or the Array for each model, if it is a biological * assembly with multiple models. * * @param structure * @return representative Atom[] */ public static Atom[] getRepresentativeAtoms(Structure structure) { if (structure.isNmr()) return StructureTools.getRepresentativeAtomArray(structure); else { // Get Atoms of all models List<Atom> atomList = new ArrayList<Atom>(); for (int m = 0; m < structure.nrModels(); m++) { for (Chain c : structure.getModel(m)) atomList.addAll(Arrays.asList(StructureTools .getRepresentativeAtomArray(c))); } return atomList.toArray(new Atom[0]); } }
Example 3
Source File: TestMmtfUtils.java From biojava with GNU Lesser General Public License v2.1 | 6 votes |
/** * Function to get all the atoms in the strucutre as a list. * @param bioJavaStruct the biojava structure * @return a list of all the unique atoms in the structure */ private List<Atom> getAllAtoms(Structure bioJavaStruct) { // Get all the atoms List<Atom> theseAtoms = new ArrayList<Atom>(); for (int i=0; i<bioJavaStruct.nrModels(); i++){ List<Chain> chains = bioJavaStruct.getModel(i); for (Chain c : chains) { for (Group g : c.getAtomGroups()) { for(Atom a: MmtfUtils.getAtomsForGroup(g)){ theseAtoms.add(a); } } } } return theseAtoms; }
Example 4
Source File: CifFileConsumerIntegrationTest.java From biojava with GNU Lesser General Public License v2.1 | 6 votes |
private void checkNMR(Structure s) { assertTrue(s.isNmr()); int models = s.nrModels(); assertTrue(models > 0); List<Chain> model0 = s.getModel(0); // compare with all others for (int i = 1; i < models; i++) { List<Chain> modelX = s.getModel(i); assertEquals(model0.size(), modelX.size()); // compare lengths: for (int j = 0; j < model0.size(); j++) { Chain c1 = model0.get(j); Chain cx = modelX.get(j); assertEquals(c1.getAtomLength(), cx.getAtomLength()); assertEquals(c1.getAtomSequence(), cx.getAtomSequence()); assertEquals(c1.getAtomGroups(GroupType.AMINOACID).size(), cx.getAtomGroups(GroupType.AMINOACID).size()); assertEquals(c1.getAtomGroups(GroupType.NUCLEOTIDE).size(), cx.getAtomGroups(GroupType.NUCLEOTIDE).size()); assertEquals(c1.getAtomGroups(GroupType.HETATM).size(), cx.getAtomGroups(GroupType.HETATM).size()); } } }
Example 5
Source File: DemoChangeChemCompProvider.java From biojava with GNU Lesser General Public License v2.1 | 5 votes |
private void printStructure(Structure struc) { System.out.println(struc); //Chain c = struc.getChainByPDB("C"); String pdbid = struc.getPDBCode(); for (int i = 0; i < struc.nrModels(); i++) { // loop chain for (Chain ch : struc.getModel(i)) { if (! ch.getName().equals("A") ) continue; System.out.println(pdbid + ">>>" + ch.getName() + ">>>" + ch.getAtomSequence()); System.out.println(pdbid + ">>>" + ch.getName() + ">>>" + ch.getSeqResSequence()); // Test the getAtomGroups() and getSeqResGroups() method List<Group> group = ch.getSeqResGroups(); int seqPos = 0; for (Group gp : group) { System.out.println(ch.getName() + ":"+seqPos + ":" + gp.getResidueNumber() + ":" + gp.getPDBName() + " " + gp.getType()); seqPos++; } } } }
Example 6
Source File: MMCIFFileTools.java From biojava with GNU Lesser General Public License v2.1 | 5 votes |
/** * 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; }
Example 7
Source File: MmtfUtils.java From biojava with GNU Lesser General Public License v2.1 | 5 votes |
/** * This sets all microheterogeneous groups * (previously alternate location groups) as separate groups. * This is required because mmtf groups cannot have multiple HET codes. * @param bioJavaStruct */ public static void fixMicroheterogenity(Structure bioJavaStruct) { // Loop through the models for (int i=0; i<bioJavaStruct.nrModels(); i++){ // Then the chains List<Chain> chains = bioJavaStruct.getModel(i); for (Chain c : chains) { // Build a new list of groups List<Group> outGroups = new ArrayList<>(); for (Group g : c.getAtomGroups()) { List<Group> removeList = new ArrayList<>(); for (Group altLoc : g.getAltLocs()) { // Check if they are not equal -> microheterogenity if(! altLoc.getPDBName().equals(g.getPDBName())) { // Now add this group to the main list removeList.add(altLoc); } } // Add this group outGroups.add(g); // Remove any microhet alt locs g.getAltLocs().removeAll(removeList); // Add these microhet alt locs outGroups.addAll(removeList); } c.setAtomGroups(outGroups); } } }
Example 8
Source File: MmtfUtils.java From biojava with GNU Lesser General Public License v2.1 | 5 votes |
/** * Count the total number of groups in the structure * @param structure the input structure * @return the total number of groups */ public static int getNumGroups(Structure structure) { int count = 0; for(int i=0; i<structure.nrModels(); i++) { for(Chain chain : structure.getChains(i)){ count+= chain.getAtomGroups().size(); } } return count; }
Example 9
Source File: MmtfUtils.java From biojava with GNU Lesser General Public License v2.1 | 5 votes |
/** * Get summary information for the structure. * @param structure the structure for which to get the information. */ public static MmtfSummaryDataBean getStructureInfo(Structure structure) { MmtfSummaryDataBean mmtfSummaryDataBean = new MmtfSummaryDataBean(); // Get all the atoms List<Atom> theseAtoms = new ArrayList<>(); List<Chain> allChains = new ArrayList<>(); Map<String, Integer> chainIdToIndexMap = new LinkedHashMap<>(); int chainCounter = 0; int bondCount = 0; mmtfSummaryDataBean.setAllAtoms(theseAtoms); mmtfSummaryDataBean.setAllChains(allChains); mmtfSummaryDataBean.setChainIdToIndexMap(chainIdToIndexMap); for (int i=0; i<structure.nrModels(); i++){ List<Chain> chains = structure.getModel(i); allChains.addAll(chains); for (Chain chain : chains) { String idOne = chain.getId(); if (!chainIdToIndexMap.containsKey(idOne)) { chainIdToIndexMap.put(idOne, chainCounter); } chainCounter++; for (Group g : chain.getAtomGroups()) { for(Atom atom: getAtomsForGroup(g)){ theseAtoms.add(atom); // If both atoms are in the group if (atom.getBonds()!=null){ bondCount+=atom.getBonds().size(); } } } } } // Assumes all bonds are referenced twice mmtfSummaryDataBean.setNumBonds(bondCount/2); return mmtfSummaryDataBean; }
Example 10
Source File: TestDifficultMmCIFFiles.java From biojava with GNU Lesser General Public License v2.1 | 5 votes |
/** * The 2KSA mmCIF contains a 5 model NMR structure. The first residue of the sequence is not visible * and the models should all begin with Asp indexed as residue #2. * @throws IOException * @throws StructureException */ @Test public void test2KSA() throws IOException, StructureException { AtomCache cache = new AtomCache(); StructureIO.setAtomCache(cache); FileParsingParameters params = cache.getFileParsingParams(); params.setParseBioAssembly(true); params.setAlignSeqRes(true); StructureIO.setAtomCache(cache); cache.setUseMmCif(true); Structure sCif = StructureIO.getStructure("2KSA"); assertNotNull(sCif); // Unit test for each of the chains to show they begin with the correct first residue. for (int i = 0; i < sCif.nrModels(); i++) { List<Chain> chains = sCif.getModel(i); // Chain A first residue should start at ASP 2.. // but if replaceGroupSeqPos(PdbxPolySeqScheme ppss) is used, this is incorrect and will be 1. assertEquals(2, chains.get(0).getAtomGroup(0).getResidueNumber().getSeqNum().intValue()); } }
Example 11
Source File: TestHeaderOnly.java From biojava with GNU Lesser General Public License v2.1 | 5 votes |
/** * Scan through SeqResGroups, returns true if any have Atoms. * @param s * @return */ public boolean doSeqResHaveAtoms(Structure s) { for (int i = 0; i < s.nrModels(); i++) { for (Chain c : s.getChains(i)) { for (Group g : c.getSeqResGroups()) { if (hasAtoms(g)) return true; // Found some Atoms in a Seqres group. } } } return false; }
Example 12
Source File: MmtfStructureWriter.java From biojava with GNU Lesser General Public License v2.1 | 4 votes |
/** * Pass data from Biojava structure to another generic output type. Loops through the data * structure and calls all the set functions. * @param structure the input {@link Structure} to write * @param dataTransferInterface the generic interface that * implements all the set methods. */ public MmtfStructureWriter(Structure structure, StructureAdapterInterface dataTransferInterface) { this.mmtfDecoderInterface = dataTransferInterface; // Reset structure to consider altloc groups with the same residue number but different group names as seperate groups MmtfUtils.fixMicroheterogenity(structure); // Get the chain name to index map MmtfSummaryDataBean mmtfSummaryDataBean = MmtfUtils.getStructureInfo(structure); Map<String, Integer> chainIdToIndexMap = mmtfSummaryDataBean.getChainIdToIndexMap(); List<Atom> allAtoms = mmtfSummaryDataBean.getAllAtoms(); int numBonds = mmtfSummaryDataBean.getNumBonds(); List<Chain> allChains = mmtfSummaryDataBean.getAllChains(); mmtfDecoderInterface.initStructure(numBonds, allAtoms.size(), MmtfUtils.getNumGroups(structure), allChains.size(), structure.nrModels(), structure.getPDBCode()); // Generate the secondary structure MmtfUtils.calculateDsspSecondaryStructure(structure); // Get the header and the xtal info. PDBHeader pdbHeader = structure.getPDBHeader(); PDBCrystallographicInfo xtalInfo = pdbHeader.getCrystallographicInfo(); mmtfDecoderInterface.setHeaderInfo(pdbHeader.getRfree(), pdbHeader.getRwork(), pdbHeader.getResolution(), pdbHeader.getTitle(), MmtfUtils.dateToIsoString(pdbHeader.getDepDate()), MmtfUtils.dateToIsoString(pdbHeader.getRelDate()), MmtfUtils.techniquesToStringArray(pdbHeader.getExperimentalTechniques())); mmtfDecoderInterface.setXtalInfo(MmtfUtils.getSpaceGroupAsString(xtalInfo.getSpaceGroup()), MmtfUtils.getUnitCellAsArray(xtalInfo), MmtfUtils.getNcsAsArray(xtalInfo.getNcsOperators())); // Store the bioassembly data storeBioassemblyInformation(chainIdToIndexMap, pdbHeader.getBioAssemblies()); // Store the entity data storeEntityInformation(allChains, structure.getEntityInfos()); // Now loop through the data structure for (int modelIndex=0; modelIndex<structure.nrModels(); modelIndex++) { List<Chain> modelChains = structure.getChains(modelIndex); // Set this model mmtfDecoderInterface.setModelInfo(modelIndex, modelChains.size()); for(int chainInModelIndex=0; chainInModelIndex<modelChains.size(); chainInModelIndex++) { Chain chain = modelChains.get(chainInModelIndex); List<Group> groups = chain.getAtomGroups(); List<Group> sequenceGroups = chain.getSeqResGroups(); mmtfDecoderInterface.setChainInfo(chain.getId(), chain.getName(), groups.size()); for(int groupInChainIndex=0; groupInChainIndex<groups.size(); groupInChainIndex++){ Group group = groups.get(groupInChainIndex); List<Atom> atomsInGroup = MmtfUtils.getAtomsForGroup(group); ChemComp chemComp = group.getChemComp(); Character insCode = group.getResidueNumber().getInsCode(); if(insCode==null || insCode.equals(' ')){ insCode=MmtfStructure.UNAVAILABLE_CHAR_VALUE; } char singleLetterCode = 'X'; if (chemComp.getOne_letter_code().length()==1){ singleLetterCode = chemComp.getOne_letter_code().charAt(0); } mmtfDecoderInterface.setGroupInfo(group.getPDBName(), group.getResidueNumber().getSeqNum(), insCode.charValue(), chemComp.getType().toUpperCase(), atomsInGroup.size(), MmtfUtils.getNumBondsInGroup(atomsInGroup), singleLetterCode, sequenceGroups.indexOf(group), MmtfUtils.getSecStructType(group)); for (Atom atom : atomsInGroup){ char altLoc = MmtfStructure.UNAVAILABLE_CHAR_VALUE; if(atom.getAltLoc()!=null){ if(atom.getAltLoc().charValue()!=' '){ altLoc=atom.getAltLoc().charValue(); } } mmtfDecoderInterface.setAtomInfo(atom.getName(), atom.getPDBserial(), altLoc, (float) atom.getX(), (float) atom.getY(), (float) atom.getZ(), atom.getOccupancy(), atom.getTempFactor(), atom.getElement().toString(), atom.getCharge()); addBonds(atom, atomsInGroup, allAtoms); } } } } mmtfDecoderInterface.finalizeStructure(); }
Example 13
Source File: ChargeAdder.java From biojava with GNU Lesser General Public License v2.1 | 4 votes |
/** * Function to add the charges to a given structure. */ public static void addCharges(Structure structure) { // Loop through the models for(int i=0; i<structure.nrModels(); i++){ for(Chain c: structure.getChains(i)){ for(Group g: c.getAtomGroups()){ ChemComp thisChemComp = ChemCompGroupFactory.getChemComp(g.getPDBName()); List<ChemCompAtom> chemAtoms = thisChemComp.getAtoms(); for(ChemCompAtom chemCompAtom : chemAtoms) { Atom atom = g.getAtom(chemCompAtom.getAtom_id()); String stringCharge = chemCompAtom.getCharge(); short shortCharge = 0; if (stringCharge!=null){ if(!stringCharge.equals("?")){ try{ shortCharge = Short.parseShort(stringCharge); } catch(NumberFormatException e){ logger.warn("Number format exception. Parsing '"+stringCharge+"' to short"); } } else{ logger.warn("? charge on atom "+chemCompAtom.getAtom_id()+" in group "+thisChemComp.getId()); } } else{ logger.warn("Null charge on atom "+chemCompAtom.getAtom_id()+" in group "+thisChemComp.getId()); } if(atom!=null){ atom.setCharge(shortCharge); } // Now do the same for alt locs for (Group altLoc : g.getAltLocs()) { Atom altAtom = altLoc.getAtom(chemCompAtom.getAtom_id()); if(altAtom!=null){ altAtom.setCharge(shortCharge); } } } } } } }
Example 14
Source File: CifFileSupplierIntegrationTest.java From biojava with GNU Lesser General Public License v2.1 | 4 votes |
private static void testRoundTrip(String pdbId) throws IOException { URL url = new URL("https://files.rcsb.org/download/" + pdbId + ".cif"); Structure originalStruct = CifFileConverter.fromURL(url); InputStream inputStream = new ByteArrayInputStream(CifFileConverter.toText(originalStruct).getBytes()); Structure readStruct = CifFileConverter.fromInputStream(inputStream); assertNotNull(readStruct); assertEquals(originalStruct.getChains().size(), readStruct.getChains().size()); assertEquals(originalStruct.nrModels(), readStruct.nrModels()); for (int i = 0; i < originalStruct.nrModels(); i++) { assertEquals(originalStruct.getModel(i).size(), readStruct.getModel(i).size()); } for (int modelIdx = 0; modelIdx < originalStruct.nrModels(); modelIdx++) { for (int i = 0; i < originalStruct.getModel(modelIdx).size(); i++) { assertEquals(originalStruct.getChains().get(i).getAtomGroups().size(), readStruct.getChains().get(i).getAtomGroups().size()); Chain origChain = originalStruct.getModel(modelIdx).get(i); Chain readChain = readStruct.getModel(modelIdx).get(i); assertEquals(origChain.getAtomGroups().size(), readChain.getAtomGroups().size()); assertEquals(origChain.getId(), readChain.getId()); assertEquals(origChain.getName(), readChain.getName()); Atom[] origAtoms = StructureTools.getAllAtomArray(origChain); Atom[] readAtoms = StructureTools.getAllAtomArray(readChain); assertEquals(origAtoms.length, readAtoms.length); for (int atomIdx = 0; atomIdx < origAtoms.length; atomIdx++) { assertEquals("atom serials don't match for atom " + origAtoms[atomIdx].toString(), origAtoms[atomIdx].getPDBserial(), readAtoms[atomIdx].getPDBserial()); assertEquals("atom names don't match for atom " + origAtoms[atomIdx].toString(), origAtoms[atomIdx].getName(), readAtoms[atomIdx].getName()); assertEquals("atom elements don't match for atom " + origAtoms[atomIdx].toString(), origAtoms[atomIdx].getElement(), readAtoms[atomIdx].getElement()); assertEquals("x values don't match for atom " + origAtoms[atomIdx].toString(), origAtoms[atomIdx].getX(), readAtoms[atomIdx].getX(),0.0001); assertEquals("y values don't match for atom " + origAtoms[atomIdx].toString(), origAtoms[atomIdx].getY(), readAtoms[atomIdx].getY(),0.0001); assertEquals("z values don't match for atom " + origAtoms[atomIdx].toString(), origAtoms[atomIdx].getZ(), readAtoms[atomIdx].getZ(),0.0001); } } } // Test cell and symmetry assertEquals(originalStruct.getCrystallographicInfo().getSpaceGroup(), readStruct.getCrystallographicInfo().getSpaceGroup()); }
Example 15
Source File: TestMMCIFWriting.java From biojava with GNU Lesser General Public License v2.1 | 2 votes |
private static void testRoundTrip(String pdbId) throws IOException, StructureException { AtomCache cache = new AtomCache(); StructureIO.setAtomCache(cache); cache.setUseMmCif(true); FileParsingParameters params = new FileParsingParameters(); params.setAlignSeqRes(true); cache.setFileParsingParams(params); Structure originalStruct = StructureIO.getStructure(pdbId); File outputFile = File.createTempFile("biojava_testing_", ".cif"); outputFile.deleteOnExit(); FileWriter fw = new FileWriter(outputFile); fw.write(originalStruct.toMMCIF()); fw.close(); MMcifParser parser = new SimpleMMcifParser(); SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); FileParsingParameters fileParsingParams = new FileParsingParameters(); fileParsingParams.setAlignSeqRes(true); consumer.setFileParsingParameters(fileParsingParams); parser.addMMcifConsumer(consumer); parser.parse(new BufferedReader(new FileReader(outputFile))); Structure readStruct = consumer.getStructure(); assertNotNull(readStruct); assertEquals(originalStruct.getChains().size(), readStruct.getChains().size()); assertEquals(originalStruct.nrModels(), readStruct.nrModels()); for (int i=0; i<originalStruct.nrModels();i++) { assertEquals(originalStruct.getModel(i).size(), readStruct.getModel(i).size()); } for (int modelIdx=0;modelIdx<originalStruct.nrModels();modelIdx++) { for (int i=0;i<originalStruct.getModel(modelIdx).size();i++) { assertEquals(originalStruct.getChains().get(i).getAtomGroups().size(), readStruct.getChains().get(i).getAtomGroups().size()); Chain origChain = originalStruct.getModel(modelIdx).get(i); Chain readChain = readStruct.getModel(modelIdx).get(i); assertEquals(origChain.getAtomGroups().size(), readChain.getAtomGroups().size()); //assertEquals(origChain.getSeqResGroups().size(), readChain.getSeqResGroups().size()); assertEquals(origChain.getId(), readChain.getId()); assertEquals(origChain.getName(), readChain.getName()); Atom[] origAtoms = StructureTools.getAllAtomArray(origChain); Atom[] readAtoms = StructureTools.getAllAtomArray(readChain); assertEquals(origAtoms.length, readAtoms.length); for (int atomIdx=0;atomIdx<origAtoms.length;atomIdx++) { assertEquals("atom serials don't match for atom "+origAtoms[atomIdx].toString(), origAtoms[atomIdx].getPDBserial(), readAtoms[atomIdx].getPDBserial()); assertEquals("atom names don't match for atom "+origAtoms[atomIdx].toString(), origAtoms[atomIdx].getName(), readAtoms[atomIdx].getName()); assertEquals("atom elements don't match for atom "+origAtoms[atomIdx].toString(), origAtoms[atomIdx].getElement(), readAtoms[atomIdx].getElement()); assertEquals("x values don't match for atom "+origAtoms[atomIdx].toString(), origAtoms[atomIdx].getX(), readAtoms[atomIdx].getX(),0.0001); assertEquals("y values don't match for atom "+origAtoms[atomIdx].toString(), origAtoms[atomIdx].getY(), readAtoms[atomIdx].getY(),0.0001); assertEquals("z values don't match for atom "+origAtoms[atomIdx].toString(), origAtoms[atomIdx].getZ(), readAtoms[atomIdx].getZ(),0.0001); } } } // Test cell and symmetry assertEquals(originalStruct.getCrystallographicInfo().getSpaceGroup(), readStruct.getCrystallographicInfo().getSpaceGroup()); }