<commit_before>/*
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 * Created on 05.03.2004
 * @author <NAME>
 *
 */
package org.biojava.bio.structure;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.biojava.bio.structure.io.PDBParseException;
import org.biojava.bio.structure.io.mmcif.ChemCompGroupFactory;
import org.biojava.bio.structure.io.mmcif.model.ChemComp;

/**
 *
 * Generic Implementation of a Group interface.
 * AminoAcidImpl and NucleotideImpl are closely related classes.
 * @see AminoAcidImpl
 * @see NucleotideImpl
 * @author <NAME>
 * @author <NAME>
 * @version %I% %G%
 * @since 1.4
 */
public class HetatomImpl implements Group,Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 4491470432023820382L;

	/** this is a "hetatm".
	 *
	 */
	public static final String type = GroupType.HETATM ;

	Map<String, Object> properties ;

	long id;

	/* stores if 3d coordinates are available. */
	protected boolean pdb_flag ;

	/* 3 letter name of amino acid in pdb file. */
	protected String pdb_name ;

	protected ResidueNumber residueNumber;

	protected List<Atom> atoms ;

	Chain parent;

	Map<String,Atom> atomLookup = new HashMap<String,Atom>();
	Map<String,Atom> atomSingleCharLookup = new HashMap<String,Atom>();

	ChemComp chemComp ;

	List<Group> altLocs;
	
	/* Construct a Hetatom instance. */
	public HetatomImpl() {
		super();

		pdb_flag = false;
		pdb_name = null ;
		
		residueNumber = null;
		atoms    = new ArrayList<Atom>();
		properties = new HashMap<String,Object>();
		parent = null;
		chemComp = null;
		altLocs = null;
	}

	/* returns an identical copy of this structure
     public Object clone() {
     Hetatom n = new Hetatom();
     }
	 */




	/**
	 *  returns true or false, depending if this group has 3D coordinates or not.
	 * @return true if Group has 3D coordinates
	 */
	public boolean has3D() {
		return pdb_flag;
	}

	/** flag if group has 3D data.
	 *
	 * @param flag  true to set flag that this Group has 3D coordinates
	 */
	public void setPDBFlag(boolean flag){
		pdb_flag = flag ;
	}

	/**
	 * Returns the PDBCode.
	 * @see #setPDBCode
	 * @return a String representing the PDBCode value
	 * @deprecated replaced by #getSeqNum
	 */
	@Deprecated
	public String getPDBCode() {
		if ( residueNumber != null)
			return residueNumber.toString();
		return null;
	}

	/** set the PDB code.
	 * @see #getPDBCode
	 * @deprecated replaced by {@link #setResidueNumber(ResidueNumber)}
	 */
	@Deprecated
	public void setPDBCode(String pdb_code) {

		//set the residueNumber here if there isn't one already
		residueNumber = ResidueNumber.fromString(pdb_code);
		String chainId = null;
		if (parent != null) {
			chainId = parent.getName();
		}
		residueNumber.setChainId(chainId);
	
	
	}

	/** set three character name of Group .
	 *
	 * @param s  a String specifying the PDBName value
	 * @see #getPDBName
	 * @throws PDBParseException ...
	 */
	public void setPDBName(String s)
	throws PDBParseException
	{
		// hetatoms can have pdb_name length < 3. e.g. CU (see 1a4a position 1200 )
		//if (s.length() != 3) {
		//throw new PDBParseException("amino acid name is not of length 3!");
		//}
		if (s.equals("?")) System.out.println("HetatomImpl: invalid pdbname: ?");
		pdb_name =s ;
	}

	/**
	 * Returns the PDBName.
	 *
	 * @return a String representing the PDBName value
	 * @see #setPDBName
	 */
	public String getPDBName() { return pdb_name;}

	/** add an atom to this group. */
	public void addAtom(Atom atom){
		atom.setGroup(this);
		atoms.add(atom);
		if (atom.getCoords() != null){
			// we have got coordinates!
			setPDBFlag(true);
		}
		atomLookup.put(atom.getFullName(),atom);
		atomSingleCharLookup.put(atom.getName(),atom);
	};


	/** remove all atoms
	 *
	 */
	public void clearAtoms() {
		atoms.clear();
		setPDBFlag(false);
		atomLookup.clear();<commit_msg>adding check for null<commit_after>/*
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 * Created on 05.03.2004
 * @author <NAME>
 *
 */
package org.biojava.bio.structure;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.biojava.bio.structure.io.PDBParseException;
import org.biojava.bio.structure.io.mmcif.ChemCompGroupFactory;
import org.biojava.bio.structure.io.mmcif.model.ChemComp;

/**
 *
 * Generic Implementation of a Group interface.
 * AminoAcidImpl and NucleotideImpl are closely related classes.
 * @see AminoAcidImpl
 * @see NucleotideImpl
 * @author <NAME>
 * @author <NAME>
 * @version %I% %G%
 * @since 1.4
 */
public class HetatomImpl implements Group,Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 4491470432023820382L;

	/** this is a "hetatm".
	 *
	 */
	public static final String type = GroupType.HETATM ;

	Map<String, Object> properties ;

	long id;

	/* stores if 3d coordinates are available. */
	protected boolean pdb_flag ;

	/* 3 letter name of amino acid in pdb file. */
	protected String pdb_name ;

	protected ResidueNumber residueNumber;

	protected List<Atom> atoms ;

	Chain parent;

	Map<String,Atom> atomLookup = new HashMap<String,Atom>();
	Map<String,Atom> atomSingleCharLookup = new HashMap<String,Atom>();

	ChemComp chemComp ;

	List<Group> altLocs;
	
	/* Construct a Hetatom instance. */
	public HetatomImpl() {
		super();

		pdb_flag = false;
		pdb_name = null ;
		
		residueNumber = null;
		atoms    = new ArrayList<Atom>();
		properties = new HashMap<String,Object>();
		parent = null;
		chemComp = null;
		altLocs = null;
	}

	/* returns an identical copy of this structure
     public Object clone() {
     Hetatom n = new Hetatom();
     }
	 */




	/**
	 *  returns true or false, depending if this group has 3D coordinates or not.
	 * @return true if Group has 3D coordinates
	 */
	public boolean has3D() {
		return pdb_flag;
	}

	/** flag if group has 3D data.
	 *
	 * @param flag  true to set flag that this Group has 3D coordinates
	 */
	public void setPDBFlag(boolean flag){
		pdb_flag = flag ;
	}

	/**
	 * Returns the PDBCode.
	 * @see #setPDBCode
	 * @return a String representing the PDBCode value
	 * @deprecated replaced by #getSeqNum
	 */
	@Deprecated
	public String getPDBCode() {
		if ( residueNumber != null)
			return residueNumber.toString();
		return null;
	}

	/** set the PDB code.
	 * @see #getPDBCode
	 * @deprecated replaced by {@link #setResidueNumber(ResidueNumber)}
	 */
	@Deprecated
	public void setPDBCode(String pdb_code) {

		//set the residueNumber here if there isn't one already
		residueNumber = ResidueNumber.fromString(pdb_code);
		String chainId = null;
		if (parent != null) {
			chainId = parent.getName();
		}
		residueNumber.setChainId(chainId);
	
	
	}

	/** set three character name of Group .
	 *
	 * @param s  a String specifying the PDBName value
	 * @see #getPDBName
	 * @throws PDBParseException ...
	 */
	public void setPDBName(String s)
	throws PDBParseException
	{
		// hetatoms can have pdb_name length < 3. e.g. CU (see 1a4a position 1200 )
		//if (s.length() != 3) {
		//throw new PDBParseException("amino acid name is not of length 3!");
		//}
		if (s != null && s.equals("?")) System.err.println("HetatomImpl: invalid pdbname: ?");
		pdb_name =s ;
	}

	/**
	 * Returns the PDBName.
	 *
	 * @return a String representing the PDBName value
	 * @see #setPDBName
	 */
	public String getPDBName() { return pdb_name;}

	/** add an atom to this group. */
	public void addAtom(Atom atom){
		atom.setGroup(this);
		atoms.add(atom);
		if (atom.getCoords() != null){
			// we have got coordinates!
			setPDBFlag(true);
		}
		atomLookup.put(atom.getFullName(),atom);
		atomSingleCharLookup.put(atom.getName(),atom);
	};


	/** remove all atoms
	 *
	 */
	public void clearAtoms() {
		atoms.clear();
		setPDBFlag(false);
		atomLookup.clear();
{'fraction_non_alphanumeric': 0.11415272082455946, 'fraction_numerical': 0.009974509586611991, 'mean_word_length': 3.32183908045977, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3405219', 'n_tokens_mistral': 3224, 'n_tokens_neox': 2889, 'n_words': 910}