Java Code Examples for org.biojava.nbio.structure.Structure#addChain()

The following examples show how to use org.biojava.nbio.structure.Structure#addChain() . 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 vote down vote up
/**
 * 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: TestMmtfUtils.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test getting the number of groups from a structure.
 */
@Test
public void testGetNumGroups() {
	Structure structure = new StructureImpl();
	Chain chain = new ChainImpl();
	Group groupOne = new  AminoAcidImpl();
	Group groupTwo = new HetatomImpl();
	Group groupThree = new NucleotideImpl();
	structure.addChain(chain);
	chain.addGroup(groupOne);
	chain.addGroup(groupTwo);
	chain.addGroup(groupThree);
	assertEquals(3,MmtfUtils.getNumGroups(structure));
}
 
Example 3
Source File: TestMmtfUtils.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test that getting the structure data info works.
 */
@Test
public void testGetStructureInfo() {
	Structure structure = new StructureImpl();
	Chain chain = new ChainImpl();
	chain.setId("A");
	Map<String,Integer> testMap = new HashMap<>();
	testMap.put("A", 0);
	List<Chain> chainList = new ArrayList<>();
	chainList.add(chain);
	Group group = new AminoAcidImpl();
	chain.addGroup(group);
	Atom atomOne = new AtomImpl();
	Atom atomTwo = new AtomImpl();
	List<Atom> atomList = new ArrayList<>();
	atomList.add(atomOne);
	atomList.add(atomTwo);
	new BondImpl(atomOne, atomTwo, 1);
	structure.addChain(chain);
	group.addAtom(atomOne);
	group.addAtom(atomTwo);
	// Get the structure
	MmtfSummaryDataBean mmtfSummaryDataBean = MmtfUtils.getStructureInfo(structure);
	assertEquals(mmtfSummaryDataBean.getAllAtoms(), atomList);
	assertEquals(testMap, mmtfSummaryDataBean.getChainIdToIndexMap());
	assertEquals(chainList, mmtfSummaryDataBean.getAllChains());
	assertEquals(1, mmtfSummaryDataBean.getNumBonds());
}
 
Example 4
Source File: AbstractAlignmentJmol.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Create and set a new structure from a given atom array.
 * @param atoms
 */
public void setAtoms(Atom[] atoms){
	Structure s = new StructureImpl();
	Chain c = new ChainImpl();
	c.setId("A");
	for (Atom a: atoms){
		c.addGroup(a.getGroup());
	}
	s.addChain(c);
	setStructure(s);
}
 
Example 5
Source File: TestInterfaceFinder.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Create a mock structure with 2 entities 1 (chains A, B) and 2 (chain C).
 * @return a structure
 */
private Structure mockStructure() {
    Structure structure = new StructureImpl();
    EntityInfo entity1 = new EntityInfo();
    entity1.setMolId(1);
    EntityInfo entity2 = new EntityInfo();
    entity2.setMolId(2);
    structure.addEntityInfo(entity1);
    structure.addEntityInfo(entity2);

    Chain chainA = new ChainImpl();
    chainA.setId("A");
    chainA.setName("A");
    Chain chainB = new ChainImpl();
    chainB.setId("B");
    chainB.setName("B");
    entity1.addChain(chainA);
    entity1.addChain(chainB);
    Chain chainC = new ChainImpl();
    chainC.setId("C");
    chainC.setName("C");
    entity2.addChain(chainC);

    structure.addChain(chainA);
    structure.addChain(chainB);
    structure.addChain(chainC);

    // entity 1: chain A 10 observed residues, chain B 9 observed residues (first unobserved)
    List<Group> aGroups = getGroupList(10, "ALA", chainA, new Point3d(0,0,0));
    chainA.setAtomGroups(new ArrayList<>(aGroups));
    chainA.setSeqResGroups(aGroups);
    chainA.setEntityInfo(entity1);

    List<Group> bGroups = getGroupList(10, "ALA", chainB, new Point3d(4, 0, 0));
    chainB.setAtomGroups(new ArrayList<>(bGroups.subList(1,10)));
    chainB.setSeqResGroups(bGroups);
    chainB.setEntityInfo(entity1);

    List<Group> cGroups = getGroupList(20, "GLY", chainC, new Point3d(0, 4, 0));
    chainC.setAtomGroups(new ArrayList<>(cGroups));
    chainC.setSeqResGroups(cGroups);
    chainC.setEntityInfo(entity2);

    return structure;
}
 
Example 6
Source File: TestSubunitCluster.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Create a mock structure with 2 entities 1 (chains A, B) and 2 (chain C).
 * @return a structure
 */
private Structure mockStructure() {
	Structure structure = new StructureImpl();
	EntityInfo entity1 = new EntityInfo();
	entity1.setMolId(1);
	EntityInfo entity2 = new EntityInfo();
	entity2.setMolId(2);
	structure.addEntityInfo(entity1);
	structure.addEntityInfo(entity2);

	Chain chainA = new ChainImpl();
	chainA.setId("A");
	Chain chainB = new ChainImpl();
	chainB.setId("B");
	entity1.addChain(chainA);
	entity1.addChain(chainB);
	Chain chainC = new ChainImpl();
	chainC.setId("C");
	entity2.addChain(chainC);

	structure.addChain(chainA);
	structure.addChain(chainB);
	structure.addChain(chainC);

	// entity 1: chain A 10 observed residues, chain B 9 observed residues (first unobserved)
	List<Group> aGroups = getGroupList(10, "ALA", chainA);
	chainA.setAtomGroups(new ArrayList<>(aGroups));
	chainA.setSeqResGroups(aGroups);
	chainA.setEntityInfo(entity1);

	List<Group> bGroups = getGroupList(10, "ALA", chainB);
	chainB.setAtomGroups(new ArrayList<>(bGroups.subList(1,10)));
	chainB.setSeqResGroups(bGroups);
	chainB.setEntityInfo(entity1);

	List<Group> cGroups = getGroupList(20, "GLY", chainC);
	chainC.setAtomGroups(new ArrayList<>(cGroups));
	chainC.setSeqResGroups(cGroups);
	chainC.setEntityInfo(entity2);

	return structure;
}
 
Example 7
Source File: TestMMCIFWriting.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static Structure createDummyStructure() {
	Group g = new AminoAcidImpl();
	Atom a = getAtom("CA", Element.C, 1, 1, 1, 1);
	g.addAtom(a);
	g.setResidueNumber(new ResidueNumber("A", 1, null));
	Group altLocG = new AminoAcidImpl();
	Atom a2 = getAtom("CA", Element.C, 2, 2, 2, 2);
	altLocG.addAtom(a2);
	altLocG.setResidueNumber(new ResidueNumber("A", 1, null));

	g.addAltLoc(altLocG);

	Chain c1 = new ChainImpl();
	c1.addGroup(g);
	c1.setId("A");
	EntityInfo entityInfo = new EntityInfo();
	entityInfo.setMolId(1);
	entityInfo.addChain(c1);
	c1.setEntityInfo(entityInfo);

	Group gc2 = new AminoAcidImpl();
	Atom ac2 = getAtom("CA", Element.C, 3, 3, 3, 3);
	gc2.addAtom(ac2);
	gc2.setResidueNumber(new ResidueNumber("A_1", 1, null));

	Group altLocGc2 = new AminoAcidImpl();
	Atom ac22 = getAtom("CA", Element.C, 4, 4, 4, 4);
	altLocGc2.addAtom(ac22);
	altLocGc2.setResidueNumber(new ResidueNumber("A_1", 1, null));

	gc2.addAltLoc(altLocGc2);

	Chain c2 = new ChainImpl();
	c2.addGroup(gc2);
	c2.setId("A_1");
	c2.setEntityInfo(entityInfo);
	entityInfo.addChain(c2);

	Structure s = new StructureImpl();
	s.addChain(c1);
	s.addChain(c2);
	return s;
}
 
Example 8
Source File: TestMmtfStructureWriter.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Test the writing of Structure objects to a file.
 * @throws IOException
 */
@Test
public void testWrite() throws IOException {

	// Create a structure
	Structure structure = new StructureImpl();

	// Add some header information
	PDBHeader pdbHeader = new PDBHeader();
	pdbHeader.setExperimentalTechnique("X-RAY DIFFRACTION");
	structure.setPDBHeader(pdbHeader);

	// Create one chain
	structure.setEntityInfos(new ArrayList<EntityInfo>());
	Chain chain = new ChainImpl();
	chain.setId("A");
	chain.setName("A");
	Group group = new AminoAcidImpl();
	group.setPDBName("FKF");
	ChemComp chemComp = new ChemComp();
	chemComp.setType("TYPfdl");
	chemComp.setOne_letter_code("A");
	group.setChemComp(chemComp);

	// Create one Atom
	Atom atom = new AtomImpl();
	atom.setName("A");
	atom.setElement(Element.Ag);
	atom.setCoords(new double[] { 1.0, 2.0, 3.0 });

	// Link together the objects
	chain.addGroup(group);
	group.addAtom(atom);

	ResidueNumber residueNumber = new ResidueNumber();
	residueNumber.setInsCode('A');
	residueNumber.setSeqNum(100);
	group.setResidueNumber(residueNumber);

	structure.addChain(chain);

	File tempFile = testFolder.newFile("tmpfile");
	MmtfActions.writeToFile(structure, tempFile.toPath());
}
 
Example 9
Source File: PDBServerPanel.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Structure fromPDB(JTextField f, JTextField c) throws StructureException{
	String pdb = f.getText();


	if ( pdb.length() < 4) {
		f.setText("!!!");
		return null;
	}

	String chain = c.getText();
	if ( debug )
		System.out.println("file :" + pdb + " " +  chain);
	/// prepare structures

	// load them from the file system

	PDBFileReader reader = new PDBFileReader();

	reader.setPath(".");

	Structure tmp1 = new StructureImpl();

	try {
		Structure structure1 = reader.getStructureById(pdb);

		// no chain has been specified
		// return whole structure
		if (( chain == null) || (chain.length()==0)){
			return structure1;
		}
		if ( debug)
			System.out.println("using chain " + chain +  " for structure " + structure1.getPDBCode());
		Chain c1 = structure1.findChain(chain);
		tmp1.setPDBCode(structure1.getPDBCode());
		tmp1.setPDBHeader(structure1.getPDBHeader());
		tmp1.setPDBCode(structure1.getPDBCode());
		tmp1.addChain(c1);
		System.out.println("ok");

	} catch (IOException e){
		logger.warn(e.getMessage());
		throw new StructureException(e);
	}
	return tmp1;
}
 
Example 10
Source File: PDBDirPanel.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Structure fromPDB(JTextField f, JTextField c) throws StructureException{
	String pdb = f.getText();


	if ( pdb.length() < 4) {
		f.setText("!!!");
		return null;
	}

	String chain = c.getText();
	if ( debug )
		System.out.println("file :" + pdb + " " +  chain);
	/// prepare structures

	// load them from the file system



	String dir = pdbDir.getText();
	PDBFileReader reader = new PDBFileReader(dir);

	if ( debug )
		System.out.println("dir: " + dir);

	Structure tmp1 = new StructureImpl();

	try {
		Structure structure1 = reader.getStructureById(pdb);

		// no chain has been specified
		// return whole structure
		if (( chain == null) || (chain.length()==0)){
			return structure1;
		}
		if ( debug)
			System.out.println("using chain " + chain +  " for structure " + structure1.getPDBCode());
		Chain c1 = structure1.findChain(chain);
		tmp1.setPDBCode(structure1.getPDBCode());
		tmp1.setPDBHeader(structure1.getPDBHeader());
		tmp1.setPDBCode(structure1.getPDBCode());
		tmp1.addChain(c1);
		System.out.println("ok");

	} catch (IOException e){
		logger.warn(e.getMessage());
		throw new StructureException(e);
	}
	return tmp1;
}
 
Example 11
Source File: CifFileSupplierIntegrationTest.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static Structure createDummyStructure() {
    Group g = new AminoAcidImpl();
    Atom a = getAtom("CA", Element.C, 1, 1, 1, 1);
    g.addAtom(a);
    g.setResidueNumber(new ResidueNumber("A", 1, null));
    Group altLocG = new AminoAcidImpl();
    Atom a2 = getAtom("CA", Element.C, 2, 2, 2, 2);
    altLocG.addAtom(a2);
    altLocG.setResidueNumber(new ResidueNumber("A", 1, null));

    g.addAltLoc(altLocG);

    Chain c1 = new ChainImpl();
    c1.addGroup(g);
    c1.setId("A");
    EntityInfo entityInfo = new EntityInfo();
    entityInfo.setMolId(1);
    entityInfo.addChain(c1);
    c1.setEntityInfo(entityInfo);

    Group gc2 = new AminoAcidImpl();
    Atom ac2 = getAtom("CA", Element.C, 3, 3, 3, 3);
    gc2.addAtom(ac2);
    gc2.setResidueNumber(new ResidueNumber("A_1", 1, null));

    Group altLocGc2 = new AminoAcidImpl();
    Atom ac22 = getAtom("CA", Element.C, 4, 4, 4, 4);
    altLocGc2.addAtom(ac22);
    altLocGc2.setResidueNumber(new ResidueNumber("A_1", 1, null));

    gc2.addAltLoc(altLocGc2);

    Chain c2 = new ChainImpl();
    c2.addGroup(gc2);
    c2.setId("A_1");
    c2.setEntityInfo(entityInfo);
    entityInfo.addChain(c2);

    Structure s = new StructureImpl();
    s.addChain(c1);
    s.addChain(c2);
    return s;
}
 
Example 12
Source File: BiologicalAssemblyBuilder.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * 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()+SYM_CHAIN_ID_SEPARATOR+transformId);
	newChain.setName(newChain.getName()+SYM_CHAIN_ID_SEPARATOR+transformId);
	s.addChain(newChain);
}