533
/********************************************************/
534
/* scan a plane's shift list for the best energy values */
535
/********************************************************/
536
#define DEBUG_UPDATE_PLANE_ENERGY 0
537
void update_plane_energy(struct plane_pak *plane, struct model_pak *model)
541
struct plane_pak *plane2;
542
struct shift_pak *sdata;
545
g_assert(model != NULL);
546
g_assert(plane != NULL);
548
#if DEBUG_UPDATE_PLANE_ENERGY
549
printf("(%d %d %d)\n", plane->index[0], plane->index[1], plane->index[2]);
552
/* set best values to those of the 1st shift */
553
list = plane->shifts;
558
/* init the plane's best values */
559
for (i=0 ; i<2 ; i++)
561
plane->esurf[i] = sdata->esurf[i];
562
plane->esurf_shift = sdata->shift;
563
plane->eatt[i] = sdata->eatt[i];
564
plane->eatt_shift = sdata->shift;
565
plane->bbpa = sdata->bbpa;
566
plane->bbpa_shift = sdata->shift;
572
/* search the shift list for better values */
576
for (i=0 ; i<2 ; i++)
579
if (sdata->esurf[i] < plane->esurf[i])
581
plane->esurf[i] = sdata->esurf[i];
582
plane->esurf_shift = sdata->shift;
584
/* attachment energy */
585
if (sdata->eatt[i] > plane->eatt[i])
587
plane->eatt[i] = sdata->eatt[i];
588
plane->eatt_shift = sdata->shift;
592
if (sdata->bbpa < plane->bbpa)
594
plane->bbpa = sdata->bbpa;
595
plane->bbpa_shift = sdata->shift;
597
list = g_slist_next(list);
600
#if DEBUG_UPDATE_PLANE_ENERGY
601
printf(" %f\n", plane->bbpa);
604
/* update symmetry related planes */
607
for (list=model->planes ; list ; list=g_slist_next(list))
611
if (plane2->parent == plane)
613
plane2->esurf[0] = plane->esurf[0];
614
plane2->esurf[1] = plane->esurf[1];
615
plane2->eatt[0] = plane->eatt[0];
616
plane2->eatt[1] = plane->eatt[1];
622
/*************************/
623
/* construct the surface */
624
/*************************/
625
#define MAKE_SURFACE_DEBUG 0
626
gpointer make_surface(struct model_pak *data,
627
struct plane_pak *pdata,
628
struct shift_pak *sdata)
633
struct model_pak *surf;
634
struct core_pak *core;
637
g_assert(data != NULL);
638
if (data->periodic != 3)
640
gui_text_show(ERROR, "base model is not 3D periodic.\n");
643
if (!pdata->index[0] && !pdata->index[1] && !pdata->index[2])
645
gui_text_show(ERROR, "Don't be silly.\n");
649
#if MAKE_SURFACE_DEBUG
650
printf("Generating surface for model: %d\n", source);
653
/* ignore mols when building surface? */
654
bmode = data->build_molecules;
655
if (data->surface.ignore_bonding)
657
data->build_molecules = FALSE;
659
connect_molecules(data);
662
/* allocate & init for surface data */
665
/* NEW - label it as MARVIN, so it's build mode follows the */
666
/* source model, rather than the GULP setup data - see model_prep() */
669
/* transfer appropriate GULP setup data to new model */
670
gulp_data_copy(data, surf);
672
surf->gulp.run = E_SINGLE;
673
surf->gulp.method = CONV;
675
/* transfer surface data to new model */
676
/* NB: memcpy would produce undesired effects if pointers were */
677
/* later added to the surface struct */
678
ARR3SET(surf->surface.miller, pdata->index);
679
surf->surface.shift = sdata->shift;
680
surf->surface.region[0] = sdata->region[0];
681
surf->surface.region[1] = sdata->region[1];
682
/* setup for region display */
683
if (surf->surface.region[0])
684
surf->region_empty[REGION1A] = FALSE;
685
if (surf->surface.region[1])
686
surf->region_empty[REGION2A] = FALSE;
688
surf->build_molecules = bmode;
690
#if MAKE_SURFACE_DEBUG
691
printf("Miller (%d,%d,%d)\n",surf->surface.miller[0]
692
,surf->surface.miller[1]
693
,surf->surface.miller[2]);
694
printf("Shift %f\n",surf->surface.shift);
695
printf("Region sizes (%d,%d)\n",surf->surface.region[0]
696
,surf->surface.region[1]);
699
/* TODO - valid shift/region size loop??? */
700
generate_surface(data, surf);
701
gulp_files_init(surf);
704
coords_init(INIT_COORDS, surf);
707
/* restore connectivity in source model */
708
if (data->surface.ignore_bonding)
710
data->build_molecules = bmode;
712
connect_molecules(data);
715
/* calculate the bulk energy needed for GULP surface calcs */
716
sbe = data->gulp.energy;
717
if (fabs(sbe) < FRACTION_TOLERANCE)
719
gui_text_show(WARNING, "Suspicious total energy. Has it been properly calculated?\n");
722
/* calc the number of region 1 atoms */
724
for (list=surf->cores ; list ; list=g_slist_next(list))
727
if (core->region == REGION1A)
731
sbe /= data->num_atoms; /* E per atom in unit cell */
732
sbe *= r1size; /* E scaled to region 1 size */
733
surf->gulp.sbulkenergy = sbe;
735
/* employ src file? */
736
tree_model_add(surf);
737
tree_select_model(surf);