Exemple #1
0
/*
 * 	error_id(+Number, ?Message)
 *
 *		Returns the appropriate error message. Fails if the
 *		message string is empty or out of range, so that it
 *		can be used to check whether the given error exists.
 */
static int
p_error_id(value valn, type tagn, value vale, type tage)
{
    Error_If_Ref(tagn);
    Check_Output_String(tage);
    if (IsInteger(tagn))
    {
	if
	(
		valn.nint < 1
		||
		valn.nint >= MAX_ERRORS
		||
		!ErrorMessage[valn.nint]
	)
	{
		Fail_;
	}
	{
	    value v;
	    Cstring_To_Prolog(ErrorMessage[valn.nint], v);
	    Return_Unify_String(vale, tage, v.ptr);
	}
    }
    else if (IsAtom(tagn))
    {
	Return_Unify_String(vale, tage, DidString(valn.did));
    }
    else
    {
	Bip_Error(TYPE_ERROR);
    }
}
int
p_print_array(value va, type ta,
	value vm, type tm)
{
        int        size = 1;  /* number of array elements */
        pword      *p;
        uword     *dim;
        dident     wdid;
        int        arity;

        Error_If_Ref(ta);
        if (IsAtom(ta))                        /* a global variable */
                wdid = va.did;
        else                                   /* an array */
        {
                Get_Functor_Did(va, ta, wdid);
                Get_Visible_Array_Header(wdid, vm, tm, p);
                if (!IsStructure(p->tag)) /* error if not prolog */
                {
                        Error(TYPE_ERROR);
                }
                dim = (uword *) p->val.ptr;
                dim++;                        /* skip the did */
                for (arity = DidArity(wdid); arity; arity--)
                        size *= *dim++;        /* compute the size */
        }
        Get_Visible_Array_Address(wdid, vm, tm, p);
        for (; size; size--, p++)
        {
                Write(p->val, p->tag, Current_Output);
                Fprintf(Current_Output, " ");
        }
        Succeed;
}        
Exemple #3
0
/////////////////////////////////////////////////
// Prolog-Value
TStr TPlVal::GetStr(TPlBs* PlBs) const {
  TChA ChA;
  if (IsInt()){ChA+=TInt::GetStr(GetInt());}
  else if (IsFlt()){ChA+=TFlt::GetStr(GetFlt());}
  else if (IsAtom()){ChA+=PlBs->GetAtomQStr(GetAtomId());}
  else if (IsTup()){PPlTup Tup=PlBs->GetTup(GetTupId()); ChA+=Tup->GetStr(PlBs);}
  else {Fail;}
  return ChA;
}
int
p_atomd(value v1, type t1)
{
        if (IsRef(t1))
        {
                Mark_Suspending_Variable(v1.ptr);
                Delay;
        }
        else
                Succeed_If(IsAtom(t1));
}
XPString::XPString(unsigned long index, const char* cp)
{
    assert(m_XPRefCountedStringAtomArraySize != 0);
    assert(m_XPRefCountedStringLastAtom != 0);
    assert(index < m_XPRefCountedStringAtomArraySize);
    m_str = setAtom(index, cp);
    assert(m_str >= m_XPRefCountedStringAtomArray && m_str < m_XPRefCountedStringAtomArray + m_XPRefCountedStringAtomArraySize);
    assert(m_str);
    if (m_str)
        m_str->AddRef();
    assert(IsAtom());
}
// special constructors: first initializes array in addition to the string into the array
//                       second initializes string into atom array
// NOTE: cp MUST point to a permanently maintainted (i.e., static) string in memory
XPString::XPString(unsigned long totalNumberOfAtoms, unsigned long index, const char* cp)
{
    //assert(m_XPRefCountedStringAtomArraySize == 0);    // was firing on the Mac side on reload.
    //assert(m_XPRefCountedStringLastAtom == 0);         // was firing on the Mac side on reload.
    //assert(m_XPRefCountedStringAtomArray == NULL);     // was firing on the Mac side on reload.
    initAtomArray(totalNumberOfAtoms);	// *** initAtomArray is a class static function, but this is a constructor! 
    assert(index < m_XPRefCountedStringAtomArraySize);
    m_str = setAtom(index, cp);
    assert(m_str);
    if (m_str)
        m_str->AddRef();
    assert(IsAtom());
}
/*
  legal_current_op(?Precedence, ?Assoc, +Operator_atom, +Module)
  checks that all arguments are valid for current_op_body/4.
  */
static int
p_legal_current_op(value v_prec, type t_prec, value v_assoc, type t_assoc, value v_op, type t_op, value v_mod, type t_mod)
{
    if (!IsRef(t_op))			/* Operator name		*/
    {
	Check_Atom_Or_Nil(v_op, t_op);
#ifdef lint
	/* v_op is set in Check_Atom_Or_Nil but not used		*/
	if (v_op.nint) return v_op.nint;
#endif /* lint */
    }
    Check_Module(t_mod, v_mod);		/* module			*/
    Check_Module_Access(v_mod, t_mod);

    if (IsAtom(t_assoc))		/* Associativity		*/
    {
	word iassoc = _get_assoc(v_assoc.did);
	if (iassoc == NIL_OP ||
	   (iassoc > FXX && (ModuleSyntax(v_mod.did)->options & ISO_RESTRICTIONS)))
	{
	    Bip_Error(RANGE_ERROR);
	}
    }
    else if (!IsRef(t_assoc))
    {
	Bip_Error(TYPE_ERROR);
    }
    
    if (IsInteger(t_prec))		/* Precedence			*/
    {
	if (v_prec.nint < 0 || v_prec.nint > 1200)
	{
	    Bip_Error(RANGE_ERROR);
	}
    }
    else if (!IsRef(t_prec))
    {
	Bip_Error(TYPE_ERROR);
    }
    Succeed_;
}
Exemple #8
0
//frees the memory associated with the node. If it is a list, it 
//will also free all the children nodes
void CLTANode::Free(ILTAAllocator* pAllocator)
{
	ASSERT(pAllocator);

	if(IsAtom())
	{
		pAllocator->FreeBlock(m_pData);
	}
	else
	{
		//first delete all the children
		for(uint32 nCurrElement = 0; nCurrElement < m_nFlags; nCurrElement++)
		{
			pAllocator->FreeNode(GetElement(nCurrElement));
		}

		//now clear the entire array
		pAllocator->FreeBlock(m_pData);
	}

	m_nFlags	= 0;
	m_pData		= NULL;
}
Exemple #9
0
int main()
{
	enum atomType { CarbonAlpha, Carbon, Nitrogen, Oxygen };
	/*enum intensityLevel {low =50 , med = 75, high = 100};
	struct helixStruct{
		int helixNum;
		int startPos;
		int endPos;
	};
	struct strand {
		int strandID;
		int startPos;
		int endPos;
	};
	struct sheetStruct {
		std::vector<strand> strands;
		std::string sheetID;
		int startPos;
		int endPos;
	};
	*/
	struct atom {
		atomType type = Carbon;
		float x = 0.0f;
		float y = 0.0f;
		float z = 0.0f;
	};
	struct residue {
		int atomCount = 0;
		int residueNum = 0;
		atom atoms[4];
		std::string chainID = "";
	};


	//std::vector<secondaryStruct> sheet(1);
	//std::vector<residue> residues;
	//std::vector<sheetStruct> sheet;
	//std::vector<helixStruct> helix;
	//std::vector<residue> ();
	std::ifstream pdbFile;
	std::ofstream skelFile;
	residue tmpResidue;
	pdbFile.open("../PDB Files/5fj6.pdb");
	skelFile.open("../PDB Files/5fj6.skel.pdb");
	if (pdbFile.is_open() && skelFile.is_open())
	{
		int currentRes = 0;
		std::string line;
		bool isHeaderLine = false;
		while (std::getline(pdbFile, line))
		{
			if (IsHeaderLine(line))
			{
				skelFile << line << std::endl;
			}
			else // this is an atom, sheet or helix
			{
				if (IsAtom(line)) {
					int atomResNbr = ToInt(line.substr(23, 4));
					if (tmpResidue.residueNum == 0)
					{
						int resNum = atoi(line.substr(23, 4).c_str());
						tmpResidue.atomCount = 1;
						tmpResidue.residueNum = resNum;
						tmpResidue.chainID = line.substr(21, 1);
						tmpResidue.atoms[tmpResidue.atomCount - 1].type = Nitrogen;
						tmpResidue.atoms[tmpResidue.atomCount - 1].x = stof(line.substr(31, 8));
						tmpResidue.atoms[tmpResidue.atomCount - 1].y = stof(line.substr(39, 8));
						tmpResidue.atoms[tmpResidue.atomCount - 1].z = stof(line.substr(47, 8));
					}
					else {
						if (tmpResidue.residueNum == atomResNbr) { // still same amino acid
							tmpResidue.atomCount++;

							switch (tmpResidue.atomCount) {
							case 1:
								tmpResidue.atoms[tmpResidue.atomCount - 1].type = Nitrogen;
								tmpResidue.atoms[tmpResidue.atomCount - 1].x = stof(line.substr(31, 8));
								tmpResidue.atoms[tmpResidue.atomCount - 1].y = stof(line.substr(39, 8));
								tmpResidue.atoms[tmpResidue.atomCount - 1].z = stof(line.substr(47, 8));
								break;
							case 2:
								tmpResidue.atoms[tmpResidue.atomCount - 1].type = CarbonAlpha;
								tmpResidue.atoms[tmpResidue.atomCount - 1].x = stof(line.substr(31, 8));
								tmpResidue.atoms[tmpResidue.atomCount - 1].y = stof(line.substr(39, 8));
								tmpResidue.atoms[tmpResidue.atomCount - 1].z = stof(line.substr(47, 8));
								break;
							case 3:
								tmpResidue.atoms[tmpResidue.atomCount - 1].type = Carbon;
								tmpResidue.atoms[tmpResidue.atomCount - 1].x = stof(line.substr(31, 8));
								tmpResidue.atoms[tmpResidue.atomCount - 1].y = stof(line.substr(39, 8));
								tmpResidue.atoms[tmpResidue.atomCount - 1].z = stof(line.substr(47, 8));
								break;
							case 4:
								tmpResidue.atoms[tmpResidue.atomCount - 1].type = Oxygen;
								tmpResidue.atoms[tmpResidue.atomCount - 1].x = stof(line.substr(31, 8));
								tmpResidue.atoms[tmpResidue.atomCount - 1].y = stof(line.substr(39, 8));
								tmpResidue.atoms[tmpResidue.atomCount - 1].z = stof(line.substr(47, 8));
								break;

							}

						}
						if (tmpResidue.residueNum != atomResNbr) { // we are on a new residue
							std::string tmpLine;
							float avgX=0.0f;
							float avgY = 0.0f;
							float avgZ = 0.0f;
							for (int i = 0; i < 4; i++) {
								avgX += tmpResidue.atoms[i].x;
								avgY += tmpResidue.atoms[i].y;
								avgZ += tmpResidue.atoms[i].z;
							}
							avgX = avgX / 4;
							avgY = avgY / 4;
							avgZ = avgZ / 4;
							//tmpLine = "ATOM      1  N   VAL A   3      18.481  17.489  41.966  1.00 33.08           N";
							/*std::ostringstream oss;
							oss << oss.width(7) << "ATOM";
							oss << oss.right << oss.width(5) << "1";
							oss << oss.right << oss.width(5) << " CA";
							oss << oss.right << oss.width(1) << " ";
							oss << oss.right << oss.width(3) << "GLY";
							oss << oss.right << oss.width(1) << tmpResidue.chainID;
							oss << oss.right << oss.width(4) << tmpResidue.residueNum;
							oss << oss.right << oss.width(8) << avgX;
							oss << oss.right << oss.width(8) << avgY;
							oss << oss.right << oss.width(8) << avgZ;
							oss << oss.right << oss.width(5) << "     ";
							oss << oss.right << oss.width(6) << "      ";
							oss << oss.right << oss.width(2) << " C";
							oss << oss.right << oss.width(2) << "  ";
							std::string outLine = oss.str();*/
							skelFile << std::setw(6) << setiosflags(std::ios_base::left) << "ATOM";
							skelFile << std::setw(5) << std::resetiosflags(std::ios::left) << "1";
							skelFile << std::setw(1) << std::resetiosflags(std::ios::left) << " ";
							skelFile << std::setw(4) << setiosflags(std::ios_base::left)  << "CA";
							skelFile << std::setw(1) << std::resetiosflags(std::ios::left) << " ";
							skelFile << std::setw(3) << "GLY";
							skelFile << std::setw(1) << " ";
							skelFile << std::setw(1) << tmpResidue.chainID;
							skelFile << std::setw(4) << tmpResidue.residueNum;
							skelFile << std::setw(4) << " ";
							skelFile << std::setw(8) << std::fixed << std::setprecision(3) << avgX;
							skelFile << std::setw(8) << std::fixed << std::setprecision(3) << avgY;
							skelFile << std::setw(8) << std::fixed << std::setprecision(3) << avgZ;
							skelFile << std::setw(6) << " ";
							skelFile << std::setw(6) << " ";
							skelFile << std::setw(10) << " ";
							skelFile << std::setw(2) << "C";
							skelFile << std::endl;;


							tmpResidue.residueNum = atomResNbr;
							tmpResidue.atomCount = 1;
							tmpResidue.chainID = line.substr(21, 1);
							switch (tmpResidue.atomCount) {
							case 1:
								tmpResidue.atoms[tmpResidue.atomCount - 1].type = Nitrogen;
								break;
							case 2:
								tmpResidue.atoms[tmpResidue.atomCount - 1].type = CarbonAlpha;
								break;
							case 3:
								tmpResidue.atoms[tmpResidue.atomCount - 1].type = Carbon;
								break;
							case 4:
								tmpResidue.atoms[tmpResidue.atomCount - 1].type = Oxygen;
								break;
							}
							tmpResidue.atoms[tmpResidue.atomCount - 1].x = stof(line.substr(31, 8));
							tmpResidue.atoms[tmpResidue.atomCount - 1].y = stof(line.substr(39, 8));
							tmpResidue.atoms[tmpResidue.atomCount - 1].z = stof(line.substr(47, 8));
						}

					}
				}

				/*if (IsStructure(line)) {
					if (line.substr(0, 5) == "HELIX") {
						std::vector<helixStruct>::iterator it;
						helixStruct tempStructure;

						tempStructure.helixNum = std::stoi(line.substr(8, 3));
						tempStructure.startPos = std::stoi(line.substr(22, 3));
						tempStructure.endPos = std::stoi(line.substr(34, 3));

						it = helix.begin();
						it = helix.insert(it, tempStructure);
					}
					if (line.substr(0, 5) == "SHEET") {

						if (sheet.size() != 0) {

						}
						else
						{
							sheetStruct tempSheet;
							strand tempstrand;
							std::string steve;

							tempstrand.strandID = stoi(line.substr(8, 3));
							tempstrand.startPos = stoi(line.substr(23, 4));
							tempstrand.endPos = stoi(line.substr(34, 4));

							tempSheet.sheetID = line.substr(12, 3);
							tempSheet.startPos = tempstrand.startPos;
							tempSheet.endPos = tempstrand.endPos;

							std::vector<strand>::iterator sit;
							std::vector<sheetStruct>::iterator it;


							sit = tempSheet.strands.begin();
							sit = tempSheet.strands.insert(sit, tempstrand);
							it = sheet.begin();
							it = sheet.insert(it, tempSheet);
							steve = sheet[0].sheetID;
							int bob = 1;



						}
					}
					skelFile << line << std::endl;
				}
				if (IsAtom(line)) {
					int residueNumber = stoi(line.substr(23, 4));

				}*/

			}
		}
		pdbFile.close();
		skelFile.close();
	}
	else std::cout << "Unable to open file";
    return 0;


}bool IsAtom(std::string line) {
static int
p_text_to_string(value v, type t, value vs, type ts)
{
    pword	*pw, *list;
    char	*s;
    int		len;
    pword	*old_tg = Gbl_Tg;

    if (IsRef(t))
    {
	Bip_Error(PDELAY_1);
    }

    if (IsString(t))
    {
	Kill_DE;
	Return_Unify_Pw(v, t, vs, ts);
    }

    if (IsAtom(t))	/* not including [] ! */
    {
	Kill_DE;
	Return_Unify_String(vs, ts, DidString(v.did));
    }

    if (IsNil(t))
    {
	Kill_DE;
	Return_Unify_String(vs, ts, empty_string);
    }

    if (IsList(t))		/* make a string from a list	*/
    {
	int element_type = 0;
	list = v.ptr;		/* space for the string header	*/
	Push_Buffer(1);		/* make minimum buffer		*/
	s = (char *) BufferStart(old_tg);	/* start of the new string */
	for(;;)			/* loop through the list	*/
	{
	    int c;
	    pw = list++;
	    Dereference_(pw);		/* get the list element	*/
	    if (IsRef(pw->tag))		/* check it		*/
	    {
		Gbl_Tg = old_tg;
		Push_var_delay(vs.ptr, ts.all);
		Push_var_delay(pw, pw->tag.all);
		Bip_Error(PDELAY);
	    }
	    else if (IsInteger(pw->tag))	/* char code */
	    {
		element_type |= 1;
		c = pw->val.nint;
		if (c < 0 || 255 < c)
		{
		    Gbl_Tg = old_tg;
		    Bip_Error(RANGE_ERROR);
		}
	    }
	    else if (IsAtom(pw->tag))		/* char atom */
	    {
		element_type |= 2;
		if (DidLength(pw->val.did) != 1)
		{
		    Gbl_Tg = old_tg;
		    Bip_Error(RANGE_ERROR);
		}
		c = DidName(pw->val.did)[0];
	    }
	    else
	    {
		Gbl_Tg = old_tg;
		Bip_Error(TYPE_ERROR);
	    }
	    *s++ = c;
	    if (s == (char *) Gbl_Tg)	/* we need another pword */
	    {
		Gbl_Tg += 1;
		Check_Gc;
	    }
	    Dereference_(list);		/* get the list tail	*/
	    if (IsRef(list->tag))
	    {
		Gbl_Tg = old_tg;
		Push_var_delay(vs.ptr, ts.all);
		Push_var_delay(list, list->tag.all);
		Bip_Error(PDELAY);
	    }
	    else if (IsList(list->tag))
		list = list->val.ptr;
	    else if (IsNil(list->tag))
		break;			/* end of the list	*/
	    else
	    {
		Gbl_Tg = old_tg;
		Bip_Error(TYPE_ERROR);
	    }
	}
	if (element_type != 1 && element_type != 2)	/* mixed type list? */
	{
	    Gbl_Tg = old_tg;
	    Bip_Error(TYPE_ERROR);
	}
	*s = '\0';			/* terminate the string		*/
	Set_Buffer_Size(old_tg, s - (char *)(old_tg + 1) + 1);
	Kill_DE;
	Return_Unify_String(vs, ts, old_tg);
    }

    Bip_Error(TYPE_ERROR);
}