mcodev31 / libmsym

molecular point group symmetry lib
MIT License
73 stars 33 forks source link

Add subgroup tables #3

Closed ghutchis closed 9 years ago

ghutchis commented 9 years ago

There should be support for "step-down" in symmetry based on subgroups. Even a simple table giving a list of subgroups from each point group would be great. (I'm thinking of cases where you have Ih or Td and want to symmetrize as a subgroup, esp. an Abelian subgroup.)

mcodev31 commented 9 years ago

There is now a subgroup API. The generation of subgroups is rather slow (0.2s for worst case Ih), so they will be generated on demand. These are all subgroups, so there will be several subgroups of the same kind. Let me know if there are any issues.

Usage example:

/* set element find symmetry etc./ int sgl = 0; msym_subgroup_t sg = NULL; if(MSYM_SUCCESS != (ret = msymGetSymmetryOperations(ctx, &msopsl, &msops))) goto err; if(MSYM_SUCCESS != (ret = msymGetSubgroups(ctx, &sgl, &sg))) goto err;

if(0 == strncmp(point_group, "Ih", 2)){
    for(int i = 0;i < sgl;i++){
        /* These are all subgroups gernerated from permutation product table, so there are many */
        for(int j = 0;j < sg[i].sopsl;j++){
            /* sg[i].sops[j] is a pointer into msops used just like the any symmetry operation */
        }

        if(0 == strncmp(sg[i].name, "Th", 2)){
            printf("Found pointgroup Ih, selecting Th\n");
            if(MSYM_SUCCESS != (ret = msymSelectSubgroup(ctx, &sg[i]))) goto err;
            /* Retreive the symmetry operations again.
             * Everything has been rebuilt, and the old msops is no longer valid
             * Neither are the equivalence sets
             */
            if(MSYM_SUCCESS != (ret = msymGetSymmetryOperations(ctx, &msopsl, &msops))) goto err;
            break;
        }
    }
}
mcodev31 commented 9 years ago

Ih should only take ~5ms now, the number of subgroups has been reduced to not include the parent group in certain cases. Anything below D50h should take under 0.3s. Closing this.