Beispiel #1
0
Residue::~Residue()
{
   int i;
    if (name != NULL)
    {
        delete [] name;
        name = NULL;
    }
    
    if (resID != NULL)
    {
        delete [] resID;
        resID = NULL;
    }
    
    if (insertionName != NULL)
    {
        delete [] insertionName;
        insertionName = NULL;
    }
    
    // Delete the atom pointers, since that is the contract when they get passed in.
    for (i=0; i<getNumberAtoms(); i++)
    {
        if (getAtom(i) != NULL)
        {
            delete getAtom(i);
            setAtom(i, NULL);
        }
    }    
}
Beispiel #2
0
//------------------------------
double MolState::getGeomDifference(MolState& other)
{
  double diff=0;
  for (int i=0; i<atoms.size(); i++)
    for (int j=0; j<CARTDIM; j++) 
      // diff+=DeltaR^2[=DetaX^2+DeltaY^2+DeltaZ^2]
      diff+= (getAtom(i).getCoord(j)-other.getAtom(i).getCoord(j)) * (getAtom(i).getCoord(j)-other.getAtom(i).getCoord(j));
  return diff;
}
Beispiel #3
0
std::vector<int> MolpherMol::MolpherMolImpl::lockAtoms(const std::vector<int> &indices, int mask) {
    std::vector<int> ret;
    for (auto& i : indices) {
		getAtom(i)->setLockingMask(mask);
        ret.push_back(i);
    }
    return ret;
}
Beispiel #4
0
std::vector<int> MolpherMol::MolpherMolImpl::lockAtoms(const std::string &SMARTS, int mask) {
    RDKit::RWMol *patt = RDKit::SmartsToMol(SMARTS);
    std::vector<RDKit::MatchVectType> hits_vect;
	std::vector<int> ret;
    if(RDKit::SubstructMatch(*rd_mol, *patt, hits_vect)) {
        for( size_t i = 0 ; i < hits_vect.size() ; ++i ) {
            for( size_t j = 0 ; j < hits_vect[i].size() ; ++j ) {
				int idx = hits_vect[i][j].second;
            	getAtom(idx)->setLockingMask(mask);
            	ret.push_back(idx);
            }
        }
    }
    return ret;
}
void X11UIEngine::sendXClientMessage(XWindow window, long mask, long l0, long l1, long l2, long l3, long l4)
{
  XClientMessageEvent xe;

  xe.type = XClientMessage;
  xe.window = window;
  xe.message_type = getAtom(X11_ATOM_WM_PROTOCOLS);
  xe.format = 32;
  xe.data.l[0] = l0;
  xe.data.l[1] = l1;
  xe.data.l[2] = l2;
  xe.data.l[3] = l3;
  xe.data.l[4] = l4;

  _XLib._XSendEvent(_display, window, false, mask, reinterpret_cast<XEvent*>(&xe));
}
XID X11UIEngine::getWMClientLeader()
{
  if (_wmClientLeader)
    return _wmClientLeader;

  XSetWindowAttributes attr;
  long clientLeader = _XLib._XCreateWindow(
    _display, _root, -1, -1, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent, 0UL, &attr);

  _XLib._XChangeProperty(
    _display, clientLeader, getAtom(X11_ATOM_WM_CLIENT_LEADER),
    XA_WINDOW, 32, PropModeReplace, (unsigned char* )&clientLeader, 1);

  _wmClientLeader = static_cast<XID>(clientLeader);
  return _wmClientLeader;
}
Beispiel #7
0
std::vector<std::shared_ptr<MolpherAtom>> MolpherMol::MolpherMolImpl::getNeighbors(int idx) {
    if (idx < 0 || idx >= atoms.size()) {
        std::runtime_error("No such atom. Index out of range: " + std::to_string(idx));
    }

    RDKit::ROMol& mol = *rd_mol;
    std::vector<std::shared_ptr<MolpherAtom>> neighbors;
    RDKit::ROMol::ADJ_ITER beg, end;
    boost::tie(beg, end) = mol.getAtomNeighbors(mol.getAtomWithIdx(idx));
    while (beg != end) {
        RDKit::Atom *neighbor = mol[*beg];
        neighbors.push_back(getAtom(neighbor->getIdx()));
        ++beg;
    }
    return neighbors;
}
Beispiel #8
0
void MolpherMol::MolpherMolImpl::lockAtom(int idx, int mask) {
    std::shared_ptr<MolpherAtom> atom = getAtom(idx);
    atom->setLockingMask(mask);
    mask = atom->getLockingMask();

    if (mask & (MolpherAtom::KEEP_NEIGHBORS | MolpherAtom::KEEP_BONDS)) {
        for (auto ngh : getNeighbors(idx)) {
            if (mask & MolpherAtom::KEEP_NEIGHBORS) {
                ngh->setLockingMask(ngh->getLockingMask() | MolpherAtom::NO_MUTATION | MolpherAtom::NO_REMOVAL);
            }
            if (mask & MolpherAtom::KEEP_BONDS) {
                ngh->setLockingMask(ngh->getLockingMask() | MolpherAtom::NO_REMOVAL);
            }
        }
    }
}
Beispiel #9
0
void LFSCCnfProof::printAtomMapping(std::ostream& os, std::ostream& paren) {
  ProofManager::var_iterator it = ProofManager::currentPM()->begin_vars();
  ProofManager::var_iterator end = ProofManager::currentPM()->end_vars();

  for (;it != end;  ++it) {
    os << "(decl_atom ";

    if (ProofManager::currentPM()->getLogic().compare("QF_UF") == 0) {
      Expr atom = getAtom(*it);
      LFSCTheoryProof::printTerm(atom, os);
    } else {
      // print fake atoms for all other logics
      os << "true ";
    }

    os << " (\\ " << ProofManager::getVarName(*it) << " (\\ " << ProofManager::getAtomName(*it) << "\n";
    paren << ")))";
  }
}
Beispiel #10
0
void ast_serialize(const ast_node_t ast,int(*func)(int,void*),void*param) {
	char*srcptr;
	/* if ast is nil, output '()' */
	/*inside_lisp = 1;*/
	if(ast==PRODUCTION_OK_BUT_EMPTY) {
		func('E', param);
		func('M', param);
		func('P', param);
		func('T', param);
		func('Y', param);
		func(0, param);
		return;
	}
	if(!ast) {
		func('(',param);
		func(')',param);
	/* if ast is pair, serialize list */
	} else if(isPair(ast)) {
		func('(',param);
		if(ast->node_flags&IS_FOREST) {
		func('@',param);
		func(' ',param);
		}
		ast_ser_list(ast,func,param);
		func(')',param);
	/* if ast is atom, output atom */
	} else if(isAtom(ast)) {
		srcptr=regstr(getAtom(ast));
		while(*srcptr!=0) {
			escape_chr(&srcptr,func,param, _LISP);
		}
/*		*output+=strlen(getAtom(ast));*/
	}
	func('\0',param);
	/*inside_lisp = 0;*/
}
//------------------------------------
//
//------------------------------------
uint8_t GUI_XvInit(GUI_WindowInfo * window, uint32_t w, uint32_t h)
{


    unsigned int ver, rel, req, ev, err;
    unsigned int port, adaptors;
    static XvAdaptorInfo *ai;
    static XvAdaptorInfo *curai;
    
#if 0
    win = gtk_widget_get_parent_window(window);
    xv_display = GDK_WINDOW_XDISPLAY(win);
//      xv_win= RootWindow(xv_display,0);
    xv_win = GDK_WINDOW_XWINDOW(GTK_WIDGET(window)->window);
#endif    

    xv_display=(Display *)window->display;
    xv_win=window->window;
    
    
#define WDN xv_display
    xv_port = 0;

    if (Success != XvQueryExtension(WDN, &ver, &rel, &req, &ev, &err))
      {
	  printf("\n Query Extension failed\n");
	  goto failed;
      }
    /* check for Xvideo support */
    if (Success != XvQueryAdaptors(WDN,
				   DefaultRootWindow(WDN), &adaptors, &ai))
      {
	  printf("\n Query Adaptor failed\n");
	  goto failed;
      }
    curai = ai;
    XvFormat *formats;
    // Dump infos
    port = 0;
    for (uint16_t i = 0; (!port) && (i < adaptors); i++)
      {
/*
XvPortID base_id;
unsigned long num_ports;
char type;
char *name;
unsigned long num_formats;
XvFormat *formats;
unsigned long num_adaptors;
*/
#ifdef VERBOSE_XV
	  printf("\n_______________________________\n");
	  printf("\n Adaptor 		: %d", i);
	  printf("\n Base ID		: %ld", curai->base_id);
	  printf("\n Nb Port	 	: %lu", curai->num_ports);
	  printf("\n Type			 	: %d,",
		 curai->type);
#define CHECK(x) if(curai->type & x) printf("|"#x);
	  CHECK(XvInputMask);
	  CHECK(XvOutputMask);
	  CHECK(XvVideoMask);
	  CHECK(XvStillMask);
	  CHECK(XvImageMask);

	  printf("\n Name			 	: %s",
		 curai->name);
	  printf("\n Num Adap	 	: %lu", curai->num_adaptors);
	  printf("\n Num fmt	 	: %lu", curai->num_formats);
#endif	  
	  formats = curai->formats;

	  //
	  uint16_t k;

	  for (k = 0; (k < curai->num_ports) && !port; k++)
	    {
		if (GUI_XvList(WDN, k + curai->base_id, &xv_format))
		    port = k + curai->base_id;
	    }


	  curai++;
      }
    //
    if (!port)
      {
	  printf("\n no port found");
	  goto failed;
      }
#ifdef 	COLORSPACE_YV12
    printf("\n Xv YV12 found at port :%d, format : %ld", port, xv_format);
#else
    printf("\n Xv YUY2 found at port :%d, format : %ld", port, xv_format);
#endif

    if (Success != XvGrabPort(WDN, port, 0))
	goto failed;
    {
	
	xv_port = port;
/*
   Display *display,
   XvPortID port,
   int id,
   char* data,
   int width,
   int height,
   XShmSegmentInfo *shminfo

*/
        
        XSetWindowAttributes xswa;
        XWindowAttributes attribs;
        static Atom xv_atom;
        unsigned long xswamask;
        int erCode;

        /* check if colorkeying is needed */
        xv_atom = getAtom( "XV_AUTOPAINT_COLORKEY" );
        if(xv_atom!=None)
        {
                XvSetPortAttribute( xv_display, xv_port, xv_atom, 1 );
        }
        else printf("No autopaint \n");

        /* if we have to deal with colorkeying ... */
        
	xvimage = XvShmCreateImage(WDN, xv_port,
				   xv_format, 0, w, h, &Shminfo);

	Shminfo.shmid = shmget(IPC_PRIVATE, xvimage->data_size,
			       IPC_CREAT | 0777);
        if(Shminfo.shmid<=0)
        {
                printf("shmget failed\n");
        }
	Shminfo.shmaddr = (char *) shmat(Shminfo.shmid, 0, 0);
	Shminfo.readOnly = False;
        if(Shminfo.shmaddr==(char *)-1)
        {
                printf("Shmat failed\n");
        }
	xvimage->data = Shminfo.shmaddr;
	XShmAttach(WDN, &Shminfo);
	XSync(WDN, False);
	erCode=shmctl(Shminfo.shmid, IPC_RMID, 0);
        if(erCode)
        {
                printf("Shmctl failed :%d\n",erCode);
        }
	memset(xvimage->data, 0, xvimage->data_size);

	xv_xgc.graphics_exposures = False;

	xv_gc = XCreateGC(xv_display, xv_win, 0L, &xv_xgc);
	
	//ADM_assert(BadWindow!=XSelectInput(xv_display, xv_win, ExposureMask | VisibilityChangeMask));

    }
    printf("\n Xv init succeedeed\n");

    return 1;
  failed:
    printf("\n Xv init failed..\n");
    return 0;
}
Beispiel #12
0
void Feld::paintEvent( QPaintEvent * )
{
    int i, j, x, y;

    QPainter paint ( this );

    paint.setPen (black);

	// spielfeld gleich zeichnen

	for (i = 0; i < FIELD_SIZE; i++)
	{
	    for (j = 0; j < FIELD_SIZE; j++)
		{
		    if(moving && i == xpos && j == ypos)
		      continue;

		    x = i * 30;
		    y = j * 30;

		    // zeichnet Randstücke
		    if (feld [i] [j] == 254) {
		      putNonAtom(i, j, Feld::None, true); continue;
		    }

		    if (feld[i][j] == 150) {
		      putNonAtom(i, j, Feld::MoveUp); continue;
		    }

		    if (feld[i][j] == 151) {
		      putNonAtom(i, j, Feld::MoveLeft); continue;
		    }
		    if (feld[i][j] == 152) {
		      putNonAtom(i, j, Feld::MoveDown); continue;
		    }

		    if (feld[i][j] == 153) {
		      putNonAtom(i, j, Feld::MoveRight); continue;
		    }

		    // zeichnet Atome
		    if (getAtom(feld [i] [j]).obj <= '9' && getAtom(feld [i] [j]).obj > '0')
			{
			    bitBlt (this, x, y, &data, (getAtom(feld [i] [j]).obj - '1') * 31, 0, 30,
				    30, CopyROP);
			}

		    // zeichnet Kristalle
		    if (getAtom(feld [i] [j]).obj == 'o')
			{
			    bitBlt (this, x, y, &data, 31, 93, 30, 30, CopyROP);
			}



		    // verbindungen zeichnen
		    if (getAtom(feld [i] [j]).obj <= '9' ||
			getAtom(feld [i] [j]).obj == 'o')
			for (int c = 0; c < MAX_CONNS_PER_ATOM; c++) {
			    char conn = getAtom(feld [i] [j]).conn[c];
			    if (!conn)
				break;

			    if (conn >= 'a' && conn <= 'a' + 8)
				bitBlt (this, x, y,
					&data, (conn - 'a') * 31, 31, 30, 30,
					XorROP);
			    else
				bitBlt (this, x, y,
					&data, (conn - 'A') * 31, 62, 30, 30,
					XorROP);

			}

		    // zeichnet Verbindungsstäbe
		    if (getAtom(feld [i] [j]).obj >= 'A' &&
			getAtom(feld [i] [j]).obj <= 'F')
			bitBlt (this, x, y,
				&data,
				(getAtom(feld [i] [j]).obj - 'A' + 2) * 31 ,
				93, 30, 30,
				CopyROP);
		}
    }
}
Beispiel #13
0
void STSDAtom::ReadVideoDescription()
{
	uint64 descBytesLeft;

	// read in Video Sample Data
	VideoDescriptionV0 *aVideoDescription;
				
	aVideoDescription = new VideoDescriptionV0;

	Read(&aVideoDescription->basefields.Size);
	Read(&aVideoDescription->basefields.DataFormat);
	Read(aVideoDescription->basefields.Reserved,6);
	Read(&aVideoDescription->basefields.DataReference);
	
	Read(&aVideoDescription->desc.Version);
	Read(&aVideoDescription->desc.Revision);
	Read(&aVideoDescription->desc.Vendor);
	Read(&aVideoDescription->desc.TemporaralQuality);
	Read(&aVideoDescription->desc.SpacialQuality);
	Read(&aVideoDescription->desc.Width);
	Read(&aVideoDescription->desc.Height);
	Read(&aVideoDescription->desc.HorizontalResolution);
	Read(&aVideoDescription->desc.VerticalResolution);
	Read(&aVideoDescription->desc.DataSize);
	// FrameCount is actually No of Frames per Sample which is usually 1
	Read(&aVideoDescription->desc.FrameCount);
	Read(aVideoDescription->desc.CompressorName,32);
	Read(&aVideoDescription->desc.Depth);
	Read(&aVideoDescription->desc.ColourTableID);

	aVideoDescription->VOLSize = 0;
	aVideoDescription->theVOL = NULL;

	theVideoDescArray[0] = aVideoDescription;

	descBytesLeft = getBytesRemaining();
	
	// May be a VOL
	// If not then seek back to where we are as it may be a complete new video description
	
	if (descBytesLeft > 0) {

		off_t pos = theStream->Position();
		// More extended atoms
		AtomBase *aAtomBase = getAtom(theStream);
				
		aAtomBase->OnProcessMetaData();
		printf("%s\n",aAtomBase->getAtomName());

		if (dynamic_cast<ESDSAtom *>(aAtomBase)) {
			// ESDS atom good
			aVideoDescription->VOLSize = aAtomBase->getDataSize();
			aVideoDescription->theVOL = (uint8 *)(malloc(aVideoDescription->VOLSize));
			memcpy(aVideoDescription->theVOL,dynamic_cast<ESDSAtom *>(aAtomBase)->getVOL(),aVideoDescription->VOLSize);
		} else {
			// Seek Back
			theStream->Seek(pos,SEEK_SET);
		}
		
		delete aAtomBase;
	}

	PRINT(("Size:Format=%ld:%ld %Ld\n",aVideoDescription->basefields.Size,aVideoDescription->basefields.DataFormat,getBytesRemaining()));
}
Beispiel #14
0
void STSDAtom::ReadSoundDescription()
{
	uint64 descBytesLeft;

	SoundDescriptionV1 *aSoundDescriptionV1;
			
	aSoundDescriptionV1 = new SoundDescriptionV1;
	Read(&aSoundDescriptionV1->basefields.Size);
	Read(&aSoundDescriptionV1->basefields.DataFormat);
	Read(aSoundDescriptionV1->basefields.Reserved,6);
	Read(&aSoundDescriptionV1->basefields.DataReference);

	aSoundDescriptionV1->VOLSize = 0;
	aSoundDescriptionV1->theVOL = NULL;

	// Read in Audio Sample Data
	// We place into a V1 description even though it might be a V0 or earlier

	Read(&aSoundDescriptionV1->desc.Version);
	Read(&aSoundDescriptionV1->desc.Revision);
	Read(&aSoundDescriptionV1->desc.Vendor);
	Read(&aSoundDescriptionV1->desc.NoOfChannels);
	Read(&aSoundDescriptionV1->desc.SampleSize);
	Read(&aSoundDescriptionV1->desc.CompressionID);
	Read(&aSoundDescriptionV1->desc.PacketSize);
	Read(&aSoundDescriptionV1->desc.SampleRate);

	if ((aSoundDescriptionV1->desc.Version == 1) && (aSoundDescriptionV1->basefields.DataFormat != AUDIO_IMA4)) {
		Read(&(aSoundDescriptionV1->samplesPerPacket));
		Read(&(aSoundDescriptionV1->bytesPerPacket));
		Read(&(aSoundDescriptionV1->bytesPerFrame));
		Read(&(aSoundDescriptionV1->bytesPerSample));
	
	} else {
		// Calculate?
		if (aSoundDescriptionV1->basefields.DataFormat == AUDIO_IMA4) {
			aSoundDescriptionV1->samplesPerPacket = 64;
			aSoundDescriptionV1->bytesPerFrame = aSoundDescriptionV1->desc.NoOfChannels * 34;

			aSoundDescriptionV1->bytesPerSample = aSoundDescriptionV1->desc.SampleSize / 8;
			aSoundDescriptionV1->bytesPerPacket = 64 * aSoundDescriptionV1->bytesPerFrame;
		} else {
			aSoundDescriptionV1->bytesPerSample = aSoundDescriptionV1->desc.SampleSize / 8;
			aSoundDescriptionV1->bytesPerFrame = aSoundDescriptionV1->desc.NoOfChannels * aSoundDescriptionV1->bytesPerSample;
			aSoundDescriptionV1->bytesPerPacket = aSoundDescriptionV1->desc.PacketSize;
			aSoundDescriptionV1->samplesPerPacket = aSoundDescriptionV1->desc.PacketSize / aSoundDescriptionV1->bytesPerFrame;
		}
	}

	// 0 means we dont have one
	aSoundDescriptionV1->theWaveFormat.format_tag = 0;

	descBytesLeft = getBytesRemaining();

	while (descBytesLeft > 0) {

		// More extended atoms
		AtomBase *aAtomBase = getAtom(theStream);
				
		aAtomBase->OnProcessMetaData();
		printf("%s\n",aAtomBase->getAtomName());

		if (dynamic_cast<WAVEAtom *>(aAtomBase)) {
			// WAVE atom
			aSoundDescriptionV1->theWaveFormat = dynamic_cast<WAVEAtom *>(aAtomBase)->getWaveFormat();
		}

		if (dynamic_cast<ESDSAtom *>(aAtomBase)) {
			// ESDS atom good
			aSoundDescriptionV1->VOLSize = aAtomBase->getDataSize();
			aSoundDescriptionV1->theVOL = (uint8 *)(malloc(aSoundDescriptionV1->VOLSize));
			memcpy(aSoundDescriptionV1->theVOL,dynamic_cast<ESDSAtom *>(aAtomBase)->getVOL(),aSoundDescriptionV1->VOLSize);
		}
		
		if ((aAtomBase->getAtomSize() > 0) && (descBytesLeft >= aAtomBase->getAtomSize())) {
			descBytesLeft = descBytesLeft - aAtomBase->getAtomSize();
		} else {
			DEBUGGER("Invalid Atom found when reading Sound Description\n");
			descBytesLeft = 0;
		}
				
		delete aAtomBase;
	}
			
	theAudioDescArray[0] = aSoundDescriptionV1;

	PRINT(("Size:Format=%ld:%ld %Ld\n",aSoundDescriptionV1->basefields.Size,aSoundDescriptionV1->basefields.DataFormat,descBytesLeft));
}
Beispiel #15
0
void CMOVAtom::OnProcessMetaData()
{
	BMallocIO *theUncompressedData;
	uint8 *outBuffer;
	CMVDAtom *aCMVDAtom = NULL;
	uint32	compressionID = 0;
	uint64	descBytesLeft;
	uint32	Size;
	
	descBytesLeft = getAtomSize();
	
	// Check for Compression Type
	while (descBytesLeft > 0) {
		AtomBase *aAtomBase = getAtom(theStream);
	
		aAtomBase->OnProcessMetaData();
		printf("%s [%Ld]\n",aAtomBase->getAtomName(),aAtomBase->getAtomSize());

		if (aAtomBase->getAtomSize() > 0) {
			descBytesLeft = descBytesLeft - aAtomBase->getAtomSize();
		} else {
			printf("Invalid Atom found when reading Compressed Headers\n");
			descBytesLeft = 0;
		}

		if (dynamic_cast<DCOMAtom *>(aAtomBase)) {
			// DCOM atom
			compressionID = dynamic_cast<DCOMAtom *>(aAtomBase)->getCompressionID();
			delete aAtomBase;
		} else {
			if (dynamic_cast<CMVDAtom *>(aAtomBase)) {
				// CMVD atom
				aCMVDAtom = dynamic_cast<CMVDAtom *>(aAtomBase);
				descBytesLeft = 0;
			}
		}
	}

	// Decompress data
	if (compressionID == 'zlib') {
		Size = aCMVDAtom->getUncompressedSize();
		
		outBuffer = (uint8 *)(malloc(Size));
		
		printf("Decompressing %ld bytes to %ld bytes\n",aCMVDAtom->getBufferSize(),Size);
		int result = uncompress(outBuffer, &Size, aCMVDAtom->getCompressedData(), aCMVDAtom->getBufferSize());
		
		if (result != Z_OK) {
			printf("Failed to decompress headers uncompress returned ");
			switch (result) {
				case Z_MEM_ERROR:
					DEBUGGER("Lack of Memory Error\n");
					break;
				case Z_BUF_ERROR:
					DEBUGGER("Lack of Output buffer space Error\n");
					break;
				case Z_DATA_ERROR:
					DEBUGGER("Input Data is corrupt or not a compressed set Error\n");
					break;
			}
		}

		// Copy uncompressed data into BMAllocIO
		theUncompressedData = new BMallocIO();
		theUncompressedData->SetSize(Size);
		theUncompressedData->WriteAt(0L,outBuffer,Size);
		
		free(outBuffer);
		delete aCMVDAtom;
		
		// reset position on BMAllocIO
		theUncompressedData->Seek(SEEK_SET,0L);
		// Assign to Stream
		theUncompressedStream = theUncompressedData;
		
		// All subsequent reads should use theUncompressedStream
	}

}
Beispiel #16
0
//------------------------------
bool MolState::Read()
{
  int i,j,k,l;
  char tmpCh;
  std::string tmp_str, tmp_atomName;
  std::istringstream tmp_iStr;
  Atom tmp_atom;

  //------------ Read IP (if provided) ----------------------------------

  if ( xmlF.CheckSubNode("ip") )
    {
      xmlF.node("ip");
      energy = xmlF.getDoubleValue();
      xmlF.stepBack();
    }
  //------------ Read the Geometry --------------------------------------
  
  xmlF.node("geometry");
  
  int tmp_nAtoms, tmp_nNormMds;
  tmp_nAtoms=xmlF.getIntValue("number_of_atoms");
 
  std::string units;
  units=xmlF.value("units");

  ifLinear= xmlF.getBoolValue("linear"); 
  if (ifLinear) 
    tmp_nNormMds = (3*tmp_nAtoms - 5);
  else
    tmp_nNormMds = (3*tmp_nAtoms - 6);

  tmp_iStr.str(xmlF.value("text")); 
  tmp_iStr.clear();
  atoms.clear();

  for (i=0; i<tmp_nAtoms; i++)
    {
      tmp_atomName="";
      tmpCh=' ';

      while ( !ifLetterOrNumber(tmpCh) and !(tmp_iStr.fail()) )
	tmp_iStr.get(tmpCh);  

      if (tmp_iStr.fail())
	{
	  std::cout << "\nError: less then "<< tmp_nAtoms <<" atoms found or the format error, \"text\"-s line nuumber "<<i+1<<"\n";
	  xmlF.exitOnFormatError(true);
	}
      
      do {  
	tmp_atomName+=tmpCh; 
	tmp_iStr.get( tmpCh );  
      } while( ifLetterOrNumber(tmpCh) );
      tmp_atom.Name() = tmp_atomName;

      for (k=0; k<CARTDIM; k++)
	{
	  tmp_iStr >> tmp_atom.Coord(k);
	  if (units=="au")
	    tmp_atom.Coord(k)*=AU2ANGSTROM;
	}

      if (tmp_iStr.fail())
	{
	  std::cout << "\nError: less then "<< tmp_nAtoms <<" atoms found or the format error in the atomic coordinates,\n"
		    << "       \"text\"-s line number "<<i+1<<"\n";
	  xmlF.exitOnFormatError(true);
	}
      
      atoms.push_back(tmp_atom);
    }


  
  //------------ Convert atomic names to masses --------------------------

   for (i=0; i<NAtoms(); i++)
    {
      tmp_iStr.str( amuF.reset().node("masses").node(  getAtom(i).Name().c_str()   ).value() ); 
      tmp_iStr.clear();
      tmp_iStr >> getAtom(i).Mass(); 
      amuF.exitOnFormatError(tmp_iStr.fail());
    }

  //------------ Read Normal Modes ---------------------------------------
  NormalMode tmp_normMode(NAtoms(),0); // one temp. norm mode

  normModes.clear();

  xmlF.stepBack();
  xmlF.node("normal_modes");

  tmp_iStr.str(xmlF.value("text")); 
  tmp_iStr.clear();

  for (i=0; i < tmp_nNormMds; i++)
    normModes.push_back( tmp_normMode );
 
  int nModesPerLine=3;  // three number of vib. modes per Line

  int nLines;
  nLines = tmp_nNormMds / nModesPerLine;
  if ( tmp_nNormMds % nModesPerLine != 0)
    nLines++;

  for (k = 0; k < nLines; k++)  // number of blocks with 3 norm.modes. ("lines")
    {
      int current_nModesPerLine = nModesPerLine;
      // for the last entree, nModesPerString may differ from 3
      if (nLines - 1 == k)
  	if ( tmp_nNormMds % nModesPerLine != 0 )
	  current_nModesPerLine = tmp_nNormMds % nModesPerLine;
 
      for (i=0; i < NAtoms(); i++)   
  	for (j=0; j < current_nModesPerLine; j++) 
  	  for (l=0; l < CARTDIM; l++)
	    {
	      tmp_iStr >> normModes[k*nModesPerLine+j].getDisplacement()[i*CARTDIM+l]; 
	      if (tmp_iStr.fail())
		{
		  std::cout << "\nError: less normal modes found than expected or the format error\n";
		  xmlF.exitOnFormatError(true);
		}
	    }
    }
   
  //------------ Read Frequencies ----------------------------------------
  xmlF.stepBack();
  xmlF.node("frequencies");

  tmp_iStr.str(xmlF.value("text")); 
  tmp_iStr.clear();
  
  for (i=0; i < tmp_nNormMds; i++)
    {
      tmp_iStr >> getNormMode(i).getFreq();
      if (tmp_iStr.fail())
	{
	  std::cout << "\nError: format error at frequency #"<<i<< " or less than " << tmp_nNormMds <<" frequencies found\n";
	  xmlF.exitOnFormatError(true);
	}
      if (getNormMode(i).getFreq()<=0)
	{
	  std::cout <<"\nError. The frequency ["<<getNormMode(i).getFreq() <<"] is negative\n";
	  xmlF.exitOnFormatError(true);
	}
    }

  // Now MolState is in a good shape, and some transformations can be performed

  //------------ 1. Un-mass-weight normal modes----------------------------

  xmlF.stepBack();
  xmlF.node("normal_modes");
  bool if_massweighted;
  if_massweighted=xmlF.getBoolValue("if_mass_weighted");

  //------------ 1. mass un-weight normal modes, if needed (QChem-->ACES format; )----------------
  // qchem if_massweighted="true"; aces if_massweighted="false";
  reduced_masses.Adjust(NNormModes(),1);
  reduced_masses.Set(1);
  if (if_massweighted)
    {

      // Read atomic names from "...->normal_modes->atoms"
      std::vector<Atom> normalModeAtoms;

      tmp_iStr.str(xmlF.value("atoms")); 
      tmp_iStr.clear();
      normalModeAtoms.clear();

      for (i=0; i<NAtoms(); i++)
	{
	  tmp_atomName="";
	  tmpCh=' ';

	  while ( !ifLetterOrNumber(tmpCh) and !(tmp_iStr.fail()) )
	    tmp_iStr.get(tmpCh);  

	  xmlF.exitOnFormatError(tmp_iStr.fail());
      
	  do {  
	    tmp_atomName+=tmpCh; 
	    tmp_iStr.get( tmpCh );  
	  } while( ifLetterOrNumber(tmpCh) );
	  tmp_atom.Name() = tmp_atomName;
	  normalModeAtoms.push_back(tmp_atom);
	}
      // Get masses for each atomic name:
      for (i=0; i<NAtoms(); i++)
	{
	  tmp_iStr.str( amuF.reset().node("masses").node(  normalModeAtoms[i].Name().c_str()   ).value() ); 
	  tmp_iStr.clear();
	  tmp_iStr >> normalModeAtoms[i].Mass(); 
	  amuF.exitOnFormatError(tmp_iStr.fail());
	}
      // Mass-un-weight normal modes:
      for (int nm=0; nm<NNormModes(); nm++)
	for (int a=0; a<NAtoms(); a++)
	  for (int i=0; i<CARTDIM; i++ )
	    getNormMode(nm).getDisplacement().Elem1(a*CARTDIM+i) *= sqrt(normalModeAtoms[a].Mass());

      // normolize each normal mode (/sqrt(norm) which is also /sqrt(reduced mass)):
      // KMatrix reduced_masses(NNormModes(),1);
      for (int nm=0; nm<NNormModes(); nm++)
	{
	  reduced_masses[nm] = 0;
	  for (int a=0; a<NAtoms(); a++)
	    for (int i=0; i<CARTDIM; i++ )
	      reduced_masses[nm]+= getNormMode(nm).getDisplacement().Elem1(a*CARTDIM+i) * getNormMode(nm).getDisplacement().Elem1(a*CARTDIM+i);
	}
      // reduced_masses.Print("Reduced masses:");
      // Normalize:
      for (int nm=0; nm<NNormModes(); nm++)
	for (int a=0; a<NAtoms(); a++)
	  for (int i=0; i<CARTDIM; i++ )
	    getNormMode(nm).getDisplacement().Elem1(a*CARTDIM+i)/=sqrt(reduced_masses[nm]);

    }
  xmlF.stepBack();

  //------------ 2. Align geometry if requested ----------------------------
  if_aligned_manually=false;
  double man_rot_x, man_rot_y, man_rot_z;
  Vector3D man_shift;
  if ( xmlF.CheckSubNode("manual_coordinates_transformation") )
     {
       xmlF.node("manual_coordinates_transformation");
       
       man_rot_x=xmlF.getDoubleValue("rotate_around_x"); 
       man_rot_y=xmlF.getDoubleValue("rotate_around_y"); 
       man_rot_z=xmlF.getDoubleValue("rotate_around_z"); 

       man_shift.getCoord(0)=-xmlF.getDoubleValue("shift_along_x"); 
       man_shift.getCoord(1)=-xmlF.getDoubleValue("shift_along_y"); 
       man_shift.getCoord(2)=-xmlF.getDoubleValue("shift_along_z"); 
       
       std::cout << "Molecular structure and normal modes of this electronic state\nwill be transformed as requested in the input.\n";

       shiftCoordinates(man_shift);
       rotate(man_rot_x*PI,man_rot_y*PI,man_rot_z*PI);
       applyCoordinateThreshold(COORDINATE_THRESHOLD);
       if_aligned_manually=true;

       xmlF.stepBack();
     }


  //------------ 3. Reorder normal modes if requested --------------------
   if ( xmlF.CheckSubNode("manual_normal_modes_reordering") )
    {
      xmlF.node("manual_normal_modes_reordering");
      if_nm_reordered_manually=false;
      normModesOrder.clear();

      std::cout << "New normal modes order was requested:\n" << xmlF.value("new_order") <<"\n";
      tmp_iStr.str(xmlF.value("new_order")); 
      int tmpInt;
      for (int nm=0; nm < NNormModes(); nm++)
	{
	  tmp_iStr >> tmpInt;
	  //input error check:
	  if (tmp_iStr.fail())
	    {
	      std::cout << "\nFormat error: non numeric symbol or less entries then the number of normal modes\n\n";
	      xmlF.exitOnFormatError(true);
	    }
	  if ( (tmpInt<0) or (tmpInt>=NNormModes()) )
	    {
	      std::cout << "\nError: normal mode number ["<< tmpInt<<"] is out of range [0.."<<NNormModes()-1<<"].\n\n";
	      xmlF.exitOnFormatError(true);
	    }
	  normModesOrder.push_back(tmpInt);
	}
      
      // check if there are duplicates in the list:
      std::vector<int> tmpIntVector, tmpIntVector2;
      tmpIntVector = normModesOrder;
      std::sort( tmpIntVector.begin(), tmpIntVector.end() );
      tmpIntVector2 = tmpIntVector;
      std::vector<int>::const_iterator intVec_iter;
      intVec_iter= unique( tmpIntVector.begin(), tmpIntVector.end() );
      if (intVec_iter != tmpIntVector.end())
	{
	  std::cout << "\nFormat error: there are non unique entries. Check the sorted list:\n";
	  for (std::vector<int>::const_iterator tmp_iter=tmpIntVector2.begin(); tmp_iter!=tmpIntVector2.end(); tmp_iter++)
	    std::cout << ' ' << *tmp_iter;
	  std::cout<<'\n';
	  xmlF.exitOnFormatError(true);
	}
      
      // backup normal modes
      std::vector<NormalMode> oldNormModes;
      oldNormModes.clear();
      for (int nm=0; nm < NNormModes(); nm++)
	{
	  tmp_normMode = getNormMode(nm);
	  oldNormModes.push_back( tmp_normMode );
	}
      
      // copy normal modes using new order
      for (int nm=0; nm < NNormModes(); nm++)
	getNormMode(nm) = oldNormModes[  normModesOrder[nm] ];
      
      std::cout << "Normal modes were reordered accordingly.\n";
      if_nm_reordered_manually=true;

      xmlF.stepBack();
    }