Java Code Examples for org.biojava.nbio.structure.Atom#setX()

The following examples show how to use org.biojava.nbio.structure.Atom#setX() . 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: TestInterfaceFinder.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
private List<Group> getGroupList(int size, String type, Chain chain, Point3d center) {
    List<Group> list = new ArrayList<>();
    double offsetx = 0;
    double offsety = 0;
    double offsetz = 0;
    for (int i=0;i<size;i++) {
        Group g = new AminoAcidImpl();
        g.setPDBName(type);
        g.setResidueNumber(new ResidueNumber(chain.getId(), i+1, null));
        chain.addGroup(g);
        Atom a = new AtomImpl();
        a.setName(StructureTools.CA_ATOM_NAME);
        a.setX(center.x + offsetx);
        a.setY(center.y + offsety);
        a.setZ(center.z + offsetz);
        g.addAtom(a);
        list.add(g);

        if (i%3 == 0) offsetx += 1;
        if (i%3 == 1) offsety += 1;
        if (i%3 == 2) offsetz += 1;
    }

    return list;
}
 
Example 2
Source File: SimpleMMcifConsumer.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Convert a mmCIF AtomSite object to a BioJava Atom object
 *
 * @param atom the mmmcif AtomSite record
 * @return an Atom
 */
private Atom convertAtom(AtomSite atom){


	Atom a = new AtomImpl();

	a.setPDBserial(Integer.parseInt(atom.getId()));
	a.setName(atom.getLabel_atom_id());

	double x = Double.parseDouble (atom.getCartn_x());
	double y = Double.parseDouble (atom.getCartn_y());
	double z = Double.parseDouble (atom.getCartn_z());
	a.setX(x);
	a.setY(y);
	a.setZ(z);

	float occupancy = Float.parseFloat (atom.getOccupancy());
	a.setOccupancy(occupancy);

	float temp = Float.parseFloat (atom.getB_iso_or_equiv());
	a.setTempFactor(temp);

	String alt = atom.getLabel_alt_id();
	if (( alt != null ) && ( alt.length() > 0) && (! alt.equals("."))){
		a.setAltLoc(new Character(alt.charAt(0)));
	} else {
		a.setAltLoc(new Character(' '));
	}

	Element element = Element.R;
	try {
		element = Element.valueOfIgnoreCase(atom.getType_symbol());
	}  catch (IllegalArgumentException e) {
		logger.info("Element {} was not recognised as a BioJava-known element, the element will be represented as the generic element {}", atom.getType_symbol(), Element.R.name());
	}
	a.setElement(element);

	return a;

}
 
Example 3
Source File: TestAsaCalc.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Atom getAtom(double x, double y, double z) {
	Atom atom = new AtomImpl();
	AminoAcidImpl g = new AminoAcidImpl();
	g.setAminoType('A');
	atom.setGroup(g);
	atom.setName("CA");
	atom.setElement(Element.C);
	atom.setX(x);
	atom.setY(y);
	atom.setZ(z);
	return atom;
}
 
Example 4
Source File: TestMMCIFWriting.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Atom getAtom(String name, Element e, int id, double x, double y, double z) {
	Atom a = new AtomImpl();
	a.setX(x);
	a.setY(y);
	a.setZ(z);
	a.setPDBserial(id);
	a.setName(name);
	a.setElement(e);
	return a;
}
 
Example 5
Source File: TestMmtfUtils.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test getting the correct atoms from a group
 */
@Test
public void testGetAtomsForGroup() {
	Group group = new AminoAcidImpl();
	Group altLoc = new AminoAcidImpl();
	Atom atomOne = new AtomImpl();
	atomOne.setX(1.00);
	Atom atomTwo = new AtomImpl();
	atomTwo.setX(2.00);
	Atom atomThree = new AtomImpl();
	atomThree.setX(3.00);
	atomThree.setAltLoc('B');
	Atom atomFour = new AtomImpl();
	atomFour.setX(4.00);
	List<Atom> inputList = new ArrayList<>();
	inputList.add(atomOne);
	inputList.add(atomTwo);
	inputList.add(atomFour);
	inputList.add(atomThree);
	group.addAtom(atomOne);
	group.addAtom(atomTwo);
	group.addAtom(atomFour);
	altLoc.addAtom(atomOne);
	altLoc.addAtom(atomTwo);
	altLoc.addAtom(atomThree);
	group.addAltLoc(altLoc);
	List<Atom> atomList = MmtfUtils.getAtomsForGroup(group);
	assertEquals(inputList, atomList);
}
 
Example 6
Source File: CifFileSupplierIntegrationTest.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Atom getAtom(String name, Element e, int id, double x, double y, double z) {
    Atom a = new AtomImpl();
    a.setX(x);
    a.setY(y);
    a.setZ(z);
    a.setPDBserial(id);
    a.setName(name);
    a.setElement(e);
    return a;
}
 
Example 7
Source File: CEMirrorSymm.java    From symmetry with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a mirror image of a structure along the X axis.
 * 
 * @param ca2O
 *            The array of atoms to be modified
 */
public static void mirrorCoordinates(Atom[] ca2O) {
	for (int i = 0; i < ca2O.length; i++) {
		// ca2O[i].setX(-ca2O[i].getX());
		Group g = ca2O[i].getGroup();
		for (Atom a : g.getAtoms()) {
			a.setX(-a.getX());
		}
	}
}
 
Example 8
Source File: MmtfStructureReader.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void setAtomInfo(String atomName,
		int serialNumber, char alternativeLocationId, float x,
		float y, float z, float occupancy,
		float temperatureFactor,
		String element, int charge) {
	Atom atom = new AtomImpl();
	Group altGroup = null;
	atom.setPDBserial(serialNumber);
	atom.setName(atomName.trim());
	atom.setElement(Element.valueOfIgnoreCase(element));
	if(alternativeLocationId==MmtfStructure.UNAVAILABLE_CHAR_VALUE){
		alternativeLocationId = ' ';
	}
	if (alternativeLocationId != ' ') {
		// Get the altGroup
		altGroup = getCorrectAltLocGroup(alternativeLocationId);
		atom.setAltLoc(alternativeLocationId);
	} else {
		atom.setAltLoc(Character.valueOf(' '));
	}
	atom.setX(x);
	atom.setY(y);
	atom.setZ(z);
	atom.setOccupancy(occupancy);
	atom.setTempFactor(temperatureFactor);
	atom.setCharge((short) charge);
	if (altGroup == null) {
		group.addAtom(atom);
	} else {
		altGroup.setChain(chain);
		altGroup.addAtom(atom);
	}

	// IF the main group doesn't have this atom
	if (!group.hasAtom(atom.getName())) {

		// If it's not a microheterogenity case
		if (group.getPDBName().equals(atom.getGroup().getPDBName())) {
			// And it's not a deuterated case.  'nanoheterogenity'
			if(!StructureTools.hasNonDeuteratedEquiv(atom,group)){
				group.addAtom(atom);
			}
		}
	}
	atomsInGroup.add(atom);
	allAtoms[atomCounter] = atom;
	atomCounter++;
}
 
Example 9
Source File: TestAFPChainConversion.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testAFPconversion() throws Exception{

	//Fill an AFPChain with the general information
	AFPChain afp = new AFPChain("algorithm");
	afp.setName1("name1");
	afp.setName2("name2");
	afp.setVersion("1.0");
	afp.setCalculationTime(System.currentTimeMillis());
	//Generate a optimal alignment with 3 blocks and 5 residues per block
	int[][][] optAln = new int[3][][];
	for (int b=0; b<optAln.length; b++){
		int[][] block = new int[2][];
		for (int c=0; c<block.length; c++){
			int[] residues = {b+5,b+6,b+7,b+8,b+9};
			block[c] = residues;
		}
		optAln[b] = block;
	}
	afp.setOptAln(optAln);
	afp.setBlockNum(optAln.length);
	//Set the rotation matrix and shift to random numbers
	double[][] mat = {{0.13,1.5,0.84},{1.3,0.44,2.3},{1.0,1.2,2.03}};
	Matrix rot = new Matrix(mat);
	Atom shift = new AtomImpl();
	shift.setX(0.44);
	shift.setY(0.21);
	shift.setZ(0.89);
	Matrix[] blockRot = {rot,rot,rot};
	afp.setBlockRotationMatrix(blockRot);
	Atom[] blockShift = {shift,shift,shift};
	afp.setBlockShiftVector(blockShift);

	//Convert the AFPChain into a MultipleAlignment (without Atoms)
	MultipleAlignmentEnsemble ensemble =
			new MultipleAlignmentEnsembleImpl(afp,null,null,true);
	MultipleAlignment msa = ensemble.getMultipleAlignment(0);

	//Test for all the information
	assertEquals(afp.getName1(),ensemble.getStructureIdentifiers().get(0).getIdentifier());
	assertEquals(afp.getName2(), ensemble.getStructureIdentifiers().get(1).getIdentifier());
	assertEquals(afp.getAlgorithmName(), ensemble.getAlgorithmName());
	assertEquals(afp.getVersion(),ensemble.getVersion());
	assertTrue(ensemble.getCalculationTime().equals(
			afp.getCalculationTime()));
	assertEquals(afp.getBlockNum(), msa.getBlockSets().size());
	for (int b = 0; b<afp.getBlockNum(); b++){
		assertEquals(Calc.getTransformation(
				afp.getBlockRotationMatrix()[b],
				afp.getBlockShiftVector()[b]),
				msa.getBlockSet(b).getTransformations().get(1));
	}

	//Test for the scores
	assertEquals(msa.getScore(MultipleAlignmentScorer.CE_SCORE),
			(Double) afp.getAlignScore());
	assertEquals(msa.getScore(MultipleAlignmentScorer.AVGTM_SCORE),
			(Double) afp.getTMScore());
	assertEquals(msa.getScore(MultipleAlignmentScorer.RMSD),
			(Double) afp.getTotalRmsdOpt());


	//Test for the optimal alignment
	for (int b=0; b<3; b++){
		for (int c=0; c<2; c++){
			for (int res=0; res<5; res++){
				Integer afpRes = afp.getOptAln()[b][c][res];
				assertEquals(afpRes, msa.getBlock(b).
						getAlignRes().get(c).get(res));
			}
		}
	}
}