~ubuntu-branches/ubuntu/trusty/gabedit/trusty-proposed

« back to all changes in this revision

Viewing changes to src/Display/GeomOrbXYZ.c

  • Committer: Package Import Robot
  • Author(s): Daniel Leidert (dale)
  • Date: 2012-03-20 23:23:56 UTC
  • mfrom: (1.3.19)
  • Revision ID: package-import@ubuntu.com-20120320232356-40hlj06cauc6pm5o
Tags: 2.4.2-1
* New upstream release.
* debian/control: Used wrap-and-sort.
  (Standards-Version): Bumped to 3.9.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* GeomOrbXYZ.c */
2
2
/**********************************************************************************************************
3
 
Copyright (c) 2002-2011 Abdul-Rahman Allouche. All rights reserved
 
3
Copyright (c) 2002-2012 Abdul-Rahman Allouche. All rights reserved
4
4
 
5
5
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
6
documentation files (the Gabedit), to deal in the Software without restriction, including without limitation
3505
3505
        return lineg;
3506
3506
}
3507
3507
/********************************************************************************/
 
3508
static gboolean goToLine(FILE* file,char* nextString)
 
3509
{
 
3510
        static char t[BSIZE];
 
3511
        while(!feof(file))
 
3512
        {
 
3513
                if(!fgets(t,BSIZE,file))break;
 
3514
                if (strstr(t,nextString)) return TRUE;
 
3515
        }
 
3516
        return FALSE;
 
3517
}
 
3518
/********************************************************************************/
 
3519
static gboolean gl_read_geom_nbo_file(gchar *fileName)
 
3520
{
 
3521
        gchar *tmp = NULL;
 
3522
        FILE *file;
 
3523
        gint i;
 
3524
        gint k;
 
3525
        gint j=0;
 
3526
        gint uni=1;
 
3527
        gint z = 0;
 
3528
        static gchar t[BSIZE];
 
3529
        gint nAtoms, nShell, nExp;
 
3530
  
 
3531
        if ((!fileName) || (strcmp(fileName,"") == 0))
 
3532
        {
 
3533
                Message(_("Sorry\n No file selected"),_("Error"),TRUE);
 
3534
                return FALSE;
 
3535
        }
 
3536
 
 
3537
        file = FOpen(fileName, "rb");
 
3538
        if(file == NULL)
 
3539
        {
 
3540
                Message(_("Sorry\nI cannot open this file"),_("Error"),TRUE);
 
3541
                return FALSE;
 
3542
        }
 
3543
        if(!goToLine(file,"--------")) return FALSE;
 
3544
        if(!fgets(t,BSIZE,file)) return FALSE;
 
3545
        sscanf(t,"%d %d %d",&nAtoms,&nShell,&nExp);
 
3546
        if(!goToLine(file,"--------")) return FALSE;
 
3547
        free_data_all();
 
3548
        Dipole.def = FALSE;
 
3549
        GeomOrb=g_malloc(nAtoms*sizeof(TypeGeomOrb));
 
3550
        uni = 1;
 
3551
 
 
3552
        tmp = get_name_file(fileName);
 
3553
        set_status_label_info(_("File name"),tmp);
 
3554
        g_free(tmp);
 
3555
        set_status_label_info(_("File type"),"NBO");
 
3556
        set_status_label_info(_("Geometry"),_("Reading"));
 
3557
 
 
3558
        gint ix = 0;
 
3559
        j = 0;
 
3560
        for(k=0;k<nAtoms;k++) 
 
3561
        {
 
3562
                if(!fgets(t,BSIZE,file)) break;
 
3563
                sscanf(t,"%d",&z);
 
3564
                if(z<=0)
 
3565
                {
 
3566
                        ix++;
 
3567
                        continue;
 
3568
                }
 
3569
                sscanf(t,"%d %lf %lf %lf",&z, &GeomOrb[j].C[0], &GeomOrb[j].C[1], &GeomOrb[j].C[2]);
 
3570
                GeomOrb[j].Symb=get_symbol_using_z(z);
 
3571
                if(uni==1) for(i=0;i<3;i++) GeomOrb[j].C[i] *= ANG_TO_BOHR;
 
3572
                GeomOrb[j].Prop = prop_atom_get(GeomOrb[j].Symb);
 
3573
                GeomOrb[j].partialCharge = 0;
 
3574
                GeomOrb[j].nuclearCharge = get_atomic_number_from_symbol(GeomOrb[j].Symb);
 
3575
                GeomOrb[j].variable = TRUE;
 
3576
                j++;
 
3577
                
 
3578
        }
 
3579
        nAtoms -= ix;
 
3580
        Ncenters = 0;
 
3581
        if(k==nAtoms+ix) Ncenters = nAtoms;
 
3582
        fclose(file);
 
3583
        if(Ncenters == 0 )
 
3584
        {
 
3585
                g_free(GeomOrb);
 
3586
                sprintf(t,_("Sorry, I can not read this format from '%s' file\n"),fileName);
 
3587
                Message(t,_("Error"),TRUE);
 
3588
                set_status_label_info(_("File name"),_("Nothing"));
 
3589
                set_status_label_info(_("File type"),_("Nothing"));
 
3590
                set_status_label_info(_("Mol. Orb."),_("Nothing"));
 
3591
                RebuildGeom = TRUE;
 
3592
                return FALSE;
 
3593
        }
 
3594
        else
 
3595
        {
 
3596
                /* DefineType();*/
 
3597
                gint i;
 
3598
                Ntype =Ncenters;
 
3599
                for(i=0;i<Ncenters;i++) 
 
3600
                {
 
3601
                        GeomOrb[i].NumType = i;
 
3602
                        /*
 
3603
                        Type[i].Symb=g_strdup(GeomOrb[i].Symb);
 
3604
                        Type[i].N=GetNelectrons(GeomOrb[i].Symb);
 
3605
                        */
 
3606
                }
 
3607
                buildBondsOrb();
 
3608
                RebuildGeom = TRUE;
 
3609
                reset_grid_limits();
 
3610
                init_atomic_orbitals();
 
3611
                return TRUE;
 
3612
        }
 
3613
        return TRUE;
 
3614
}
 
3615
/********************************************************************************/
3508
3616
static void gl_get_charges_from_aimall_file(FILE* fd,gint N)
3509
3617
{
3510
3618
        guint taille=BSIZE;
3553
3661
        for(i=0;i<5;i++) AtomCoord[i]=g_malloc(taille*sizeof(char));
3554
3662
  
3555
3663
        t=g_malloc(taille);
3556
 
        fd = FOpen(fileName, "r");
 
3664
        fd = FOpen(fileName, "rb");
3557
3665
        if(fd ==NULL)
3558
3666
        {
3559
3667
                g_free(t);
3981
4089
        glarea_rafresh(GLArea);
3982
4090
3983
4091
/********************************************************/
 
4092
void gl_read_nbo_file(GabeditFileChooser *SelecFile, gint response_id)
 
4093
{
 
4094
        gchar *FileName;
 
4095
        if(response_id != GTK_RESPONSE_OK) return;
 
4096
        FileName = gabedit_file_chooser_get_current_file(SelecFile);
 
4097
        gtk_widget_hide(GTK_WIDGET(SelecFile));
 
4098
        while( gtk_events_pending() ) gtk_main_iteration();
 
4099
 
 
4100
        add_objects_for_new_grid();
 
4101
        gl_read_geom_nbo_file(FileName);
 
4102
        RebuildGeom = TRUE;
 
4103
        if(this_is_a_new_geometry()) free_objects_all();
 
4104
        glarea_rafresh(GLArea);
 
4105
 
4106
/********************************************************/
3984
4107
void gl_read_last_nwchem_file(GabeditFileChooser *SelecFile, gint response_id)
3985
4108
{
3986
4109
        gchar *FileName;