Beispiel #1
0
void MolconvWindow::add_molecule(molconv::moleculePtr temp_mol)
{
    d->m_system->addMolecule(temp_mol);

    d->m_GraphicsItemVector.push_back(new chemkit::GraphicsMoleculeItem(d->m_system->getMolecule(d->m_system->nMolecules() - 1).get()));
    ui->molconv_graphicsview->addItem(d->m_GraphicsItemVector.back());

    d->m_GraphicsAxisVector.push_back(new GraphicsAxisItem(temp_mol->internalOriginPosition(), temp_mol->internalBasisVectors()));
    ui->molconv_graphicsview->addItem(d->m_GraphicsAxisVector.back());

    ui->molconv_graphicsview->update();

    d->m_ListOfMolecules->insertMolecule(temp_mol);
    d->activeMolecule = temp_mol;

    ui->actionSet_internal_basis->setEnabled(true);
    ui->actionDuplicate->setEnabled(true);
    ui->actionRemove->setEnabled(true);
    ui->actionZero_Coordinates->setEnabled(true);
    ui->actionReset_Coordinates->setEnabled(true);
    ui->actionProperties->setEnabled(true);
    ui->actionAdd_To_Group->setEnabled(true);
    ui->actionAlign->setEnabled(true);

    emit new_molecule(temp_mol);
}
Beispiel #2
0
Datum
pgchem_remove_hydrogens (PG_FUNCTION_ARGS)
{
  char *molfile = NULL;
  char *smiles = NULL;
  //unsigned int *efa_array = NULL;
  MOLECULE *retval;
  MOLECULE *arg_molecule = PG_GETARG_MOLECULE_P (0);
  bool nonpolaronly = PG_GETARG_BOOL (1);

  smiles =
    ob_delete_hydrogens (SMIPTR (arg_molecule),
			 nonpolaronly ? 1 : 0);

  molfile = ob_smiles_to_mol (smiles);
  
  if(molfile == NULL || !strlen(molfile)) {
    elog (ERROR, "Molfile generation failed! Offender was :\n %s",smiles);
  } 
  //efa_array = ob_efa_array(smiles);           

  retval = new_molecule (smiles, molfile);

  free (molfile);
  free (smiles);
  //free (efa_array);

  PG_RETURN_MOLECULE_P (retval);
}
Beispiel #3
0
static MOLECULE *make_molecule(char *raw_input, int size) {
  MOLECULE *result;
  char *input = NULL;
  char *molfile = NULL;
  char *smiles = NULL;
  char *endptr;
  unsigned int new_len;
  
  if(strstr (raw_input, "M  END") != NULL) {
    input = palloc (size+sizeof(char));
    memcpy (input, raw_input, size);
    endptr = strstr (input, "M  END") + strlen("M  END")*sizeof(char);
    *endptr = 0x0;
    new_len = strlen(input);
    pfree (input);
    input=NULL;

    input = palloc (new_len + 1);
    strncpy(input,raw_input,new_len);
    input[new_len] = 0x0;
  } else {
    input = palloc (size+1);
    memcpy (input, raw_input, size);
    input[size]=0x0;
  }    
  
  if (strstr (input, "V2000") == NULL || strstr (input, "M  END") == NULL)
    {				//TODO: Bad Hack. If more fmts are needed, we need a dedicated converter function
      if (strstr (input, "V3000") != NULL && strstr (input, "M  END") != NULL) //V3000?
	{
	  molfile = ob_V3000_to_mol (input);
	  
	  if(molfile == NULL || !strlen(molfile) || strstr(molfile,"V3000")==NULL) {
	    if(molfile!=NULL) {
	      free (molfile);
	      molfile=NULL;
	    }
	    elog (ERROR, "Molfile generation failed! V3000:\n %s",input);
	  }  
  
	  smiles = ob_mol_to_smiles (input,0);
	  
	  if(smiles == NULL || !strlen(smiles)) {
	    elog (ERROR, "SMILES generation failed! Offender was :\n %s",input);
	  }  else if (!strlen(smiles)) {
	    elog (WARNING, "SMILES generation failed! Trying fallback...");
	    free (smiles);
	    smiles=NULL;

	    smiles = ob_mol_to_canonical_smiles (input,0);
            if(smiles == NULL) {
	      elog (ERROR, "Canonical SMILES generation finally failed! Offender was :\n %s",input);
            } else if (!strlen(smiles)) {
	      free(smiles);
	      smiles=NULL;
	      elog (ERROR, "SMILES generation finally failed! Offender was :\n %s",input);
	    }  
	    elog (WARNING, "Fallback OK"); 
	  }  
	} else if (strstr (input, "InChI=") != NULL) { //InChI?	
	  molfile = ob_inchi_to_mol (input);
	  
	  if(molfile == NULL || !strlen(molfile) || strstr(molfile,"V2000")==NULL) {
	    if(molfile!=NULL) free (molfile);
	    elog (ERROR, "Molfile generation failed! InChI:\n %s",input);
	  }  
      
	  smiles = ob_mol_to_smiles (molfile,0);
	  
	  if(smiles == NULL || !strlen(smiles)) {
	    elog (ERROR, "SMILES generation failed! Offender was :\n %s",input);
	  }  else if (!strlen(smiles)) {
	    elog (WARNING, "SMILES generation failed! Trying fallback...");
	    free (smiles);
	    smiles=NULL;
	    smiles = ob_mol_to_canonical_smiles (input,0);
            if(smiles == NULL) {
	      elog (ERROR, "Canonical SMILES generation finally failed! InChI:\n %s",input);
            } else if (!strlen(smiles)) {
	      free(smiles);
	      smiles=NULL;
	      elog (ERROR, "SMILES generation finally failed! InChi:\n %s",input);
	    } 
            elog (NOTICE, "Fallback OK");   
	  }  
      } else { //SMILES?       
	  molfile = ob_smiles_to_mol (input);
	  
	  if(molfile == NULL || !strlen(molfile)) {
	    if(molfile!=NULL) free (molfile);
	    elog (ERROR, "Molfile generation failed! SMILES:\n %s",input);
	  }  

	  // smiles will be free()d below, but input was palloc()ed.
	  smiles = strdup(input);
      }
    }
  else //V2000
    {
      smiles = ob_mol_to_smiles (input,0);
      
      if(smiles == NULL || !strlen(smiles)) {
	elog (ERROR, "SMILES generation failed! Offender was :\n %s",input);
      }  else if (!strlen(smiles)) {
	elog (WARNING, "SMILES generation failed! Trying fallback...");
	free (smiles);
	smiles=NULL;

	smiles = ob_mol_to_canonical_smiles (input,0);
	if(smiles == NULL) {
	  elog (ERROR, "Cacnonical SMILES generation finally failed! Offender was :\n %s",input);
	} else if (!strlen(smiles)) {
	  free(smiles);
	  smiles=NULL;
	  elog (ERROR, "SMILES generation finally failed! Offender was :\n %s",input);
	} 
	elog (NOTICE, "Fallback OK");   
      }  
      molfile = strdup(input);
    }

  if (smiles==NULL || molfile==NULL) {
    elog (ERROR,
	  "Input is not a V2000/V3000 molfile or InChI or SMILES: %s",
	  input);
  }

  result = new_molecule (smiles, molfile);

  if (smiles != NULL) {
	free (smiles);
	smiles=NULL;
  }
  if (molfile != NULL) {
	free (molfile);
	molfile=NULL;
  }    
      
  if (input != NULL) {
    pfree(input);
    input=NULL;
  }
    
  return result;
}