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

The following examples show how to use org.biojava.nbio.structure.Atom#getAltLoc() . 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: MMCIFFileTools.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Converts an Atom object to an {@link AtomSite} object.
 * @param a the atom
 * @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
 * @param atomId the atom id to be written to AtomSite
 * @return
 */
public static AtomSite convertAtomToAtomSite(Atom a, int model, String chainName, String chainId, int atomId) {

	/*
	ATOM 7    C CD  . GLU A 1 24  ? -10.109 15.374 38.853 1.00 50.05 ? ? ? ? ? ? 24  GLU A CD  1
	ATOM 8    O OE1 . GLU A 1 24  ? -9.659  14.764 37.849 1.00 49.80 ? ? ? ? ? ? 24  GLU A OE1 1
	ATOM 9    O OE2 . GLU A 1 24  ? -11.259 15.171 39.310 1.00 50.51 ? ? ? ? ? ? 24  GLU A OE2 1
	ATOM 10   N N   . LEU A 1 25  ? -5.907  18.743 37.412 1.00 41.55 ? ? ? ? ? ? 25  LEU A N   1
	ATOM 11   C CA  . LEU A 1 25  ? -5.168  19.939 37.026 1.00 37.55 ? ? ? ? ? ? 25  LEU A CA  1
	*/

	Group g = a.getGroup();

	String record ;
	if ( g.getType().equals(GroupType.HETATM) ) {
		record = "HETATM";
	} else {
		record = "ATOM";
	}

	String entityId = "0";
	String labelSeqId = Integer.toString(g.getResidueNumber().getSeqNum());
	if (g.getChain()!=null && g.getChain().getEntityInfo()!=null) {
		entityId = Integer.toString(g.getChain().getEntityInfo().getMolId());
		if (g.getChain().getEntityInfo().getType() == EntityType.POLYMER) {
			// this only makes sense for polymeric chains, non-polymer chains will never have seqres groups and there's no point in calling getAlignedResIndex
			labelSeqId = Integer.toString(g.getChain().getEntityInfo().getAlignedResIndex(g, g.getChain()));
		}
	}

	Character  altLoc = a.getAltLoc();
	String altLocStr;
	if (altLoc==null || altLoc == ' ') {
		altLocStr = MMCIF_DEFAULT_VALUE;
	} else {
		altLocStr = altLoc.toString();
	}

	Element e = a.getElement();
	String eString = e.toString().toUpperCase();
	if ( e.equals(Element.R)) {
		eString = "X";
	}

	String insCode = MMCIF_MISSING_VALUE;
	if (g.getResidueNumber().getInsCode()!=null ) {
		insCode = Character.toString(g.getResidueNumber().getInsCode());
	}

	AtomSite atomSite = new AtomSite();
	atomSite.setGroup_PDB(record);
	atomSite.setId(Integer.toString(atomId));
	atomSite.setType_symbol(eString);
	atomSite.setLabel_atom_id(a.getName());
	atomSite.setLabel_alt_id(altLocStr);
	atomSite.setLabel_comp_id(g.getPDBName());
	atomSite.setLabel_asym_id(chainId);
	atomSite.setLabel_entity_id(entityId);
	atomSite.setLabel_seq_id(labelSeqId);
	atomSite.setPdbx_PDB_ins_code(insCode);
	atomSite.setCartn_x(FileConvert.d3.format(a.getX()));
	atomSite.setCartn_y(FileConvert.d3.format(a.getY()));
	atomSite.setCartn_z(FileConvert.d3.format(a.getZ()));
	atomSite.setOccupancy(FileConvert.d2.format(a.getOccupancy()));
	atomSite.setB_iso_or_equiv(FileConvert.d2.format(a.getTempFactor()));
	atomSite.setAuth_seq_id(Integer.toString(g.getResidueNumber().getSeqNum()));
	atomSite.setAuth_comp_id(g.getPDBName());
	atomSite.setAuth_asym_id(chainName);
	atomSite.setAuth_atom_id(a.getName());
	atomSite.setPdbx_PDB_model_num(Integer.toString(model));

	return atomSite;
}
 
Example 2
Source File: MmtfStructureWriter.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 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 3
Source File: CifFileSupplierImpl.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void accept(WrappedAtom wrappedAtom) {
    Atom atom = wrappedAtom.getAtom();
    Group group = atom.getGroup();
    Chain chain = group.getChain();

    groupPDB.add(group.getType().equals(GroupType.HETATM) ? "HETATM" : "ATOM");
    id.add(wrappedAtom.getAtomId());
    Element element = atom.getElement();
    typeSymbol.add(element.equals(Element.R) ? "X" : element.toString().toUpperCase());
    labelAtomId.add(atom.getName());
    Character altLoc = atom.getAltLoc();
    if (altLoc == null || altLoc == ' ') {
        labelAltId.markNextNotPresent();
    } else {
        labelAltId.add(String.valueOf(altLoc));
    }
    labelCompId.add(group.getPDBName());
    labelAsymId.add(wrappedAtom.getChainId());
    String entityId = "0";
    int seqId = group.getResidueNumber().getSeqNum();
    if (chain.getEntityInfo() != null) {
        entityId = Integer.toString(chain.getEntityInfo().getMolId());
        if (chain.getEntityInfo().getType() == EntityType.POLYMER) {
            // this only makes sense for polymeric chains, non-polymer chains will never have seqres groups and
            // there's no point in calling getAlignedResIndex
            seqId = chain.getEntityInfo().getAlignedResIndex(group, chain);
        }
    }
    labelEntityId.add(entityId);
    labelSeqId.add(seqId);
    String insCode = "";
    if (group.getResidueNumber().getInsCode() != null ) {
        insCode = Character.toString(group.getResidueNumber().getInsCode());
    }
    if (insCode.isEmpty()) {
        pdbxPDBInsCode.markNextUnknown();
    } else {
        pdbxPDBInsCode.add(insCode);
    }
    cartnX.add(atom.getX());
    cartnY.add(atom.getY());
    cartnZ.add(atom.getZ());
    occupancy.add(atom.getOccupancy());
    bIsoOrEquiv.add(atom.getTempFactor());
    authSeqId.add(group.getResidueNumber().getSeqNum());
    authCompId.add(group.getPDBName());
    authAsymId.add(wrappedAtom.getChainName());
    authAtomId.add(atom.getName());
    pdbxPDBModelNum.add(wrappedAtom.getModel());
}
 
Example 4
Source File: FileConvert.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Print ATOM record in the following syntax
 * <pre>
 * ATOM      1  N   ASP A  15     110.964  24.941  59.191  1.00 83.44           N
 *
 * COLUMNS        DATA TYPE       FIELD         DEFINITION
 * ---------------------------------------------------------------------------------
 * 1 -  6        Record name     "ATOM  "
 * 7 - 11        Integer         serial        Atom serial number.
 * 13 - 16        Atom            name          Atom name.
 * 17             Character       altLoc        Alternate location indicator.
 * 18 - 20        Residue name    resName       Residue name.
 * 22             Character       chainID       Chain identifier.
 * 23 - 26        Integer         resSeq        Residue sequence number.
 * 27             AChar           iCode         Code for insertion of residues.
 * 31 - 38        Real(8.3)       x             Orthogonal coordinates for X in
 * Angstroms.
 * 39 - 46        Real(8.3)       y             Orthogonal coordinates for Y in
 * Angstroms.
 * 47 - 54        Real(8.3)       z             Orthogonal coordinates for Z in
 * Angstroms.
 * 55 - 60        Real(6.2)       occupancy     Occupancy.
 * 61 - 66        Real(6.2)       tempFactor    Temperature factor.
 * 73 - 76        LString(4)      segID         Segment identifier, left-justified.
 * 77 - 78        LString(2)      element       Element symbol, right-justified.
 * 79 - 80        LString(2)      charge        Charge on the atom.
 * </pre>
 * @param a
 * @param str
 * @param chainID the chain ID that the Atom will have in the output string
 */
public static void toPDB(Atom a, StringBuffer str, String chainID) {

	Group g = a.getGroup();

	GroupType type = g.getType() ;

	String record = "" ;
	if ( type.equals(GroupType.HETATM) ) {
		record = "HETATM";
	} else {
		record = "ATOM  ";
	}


	// format output ...
	String resName = g.getPDBName();
	String pdbcode = g.getResidueNumber().toString();


	int    seri       = a.getPDBserial()        ;
	String serial     = String.format("%5d",seri);
	String fullName   = formatAtomName(a);

	Character  altLoc = a.getAltLoc();
	if ( altLoc == null)
		altLoc = ' ';

	String resseq = "" ;
	if ( hasInsertionCode(pdbcode) )
		resseq     = String.format("%5s",pdbcode);
	else
		resseq     = String.format("%4s",pdbcode)+" ";

	String x          = String.format("%8s",d3.format(a.getX()));
	String y          = String.format("%8s",d3.format(a.getY()));
	String z          = String.format("%8s",d3.format(a.getZ()));
	String occupancy  = String.format("%6s",d2.format(a.getOccupancy())) ;
	String tempfactor = String.format("%6s",d2.format(a.getTempFactor()));


	String leftResName = String.format("%3s",resName);

	StringBuffer s = new StringBuffer();
	s.append(record);
	s.append(serial);
	s.append(" ");
	s.append(fullName);
	s.append(altLoc);
	s.append(leftResName);
	s.append(" ");
	s.append(chainID);
	s.append(resseq);
	s.append("   ");
	s.append(x);
	s.append(y);
	s.append(z);
	s.append(occupancy);
	s.append(tempfactor);

	Element e = a.getElement();

	String eString = e.toString().toUpperCase();

	if ( e.equals(Element.R)) {
		eString = "X";
	}
	str.append(String.format("%-76s%2s", s.toString(),eString));
	str.append(newline);

}