How to create a periodic crystal structure with lots of angle, dihedral and improper interactions efficiently

Thank you very much for the reply. In the last several days, I have looked into the discrepancy of the number of improper interactions generated by two methods. As the reply I submitted 12 days ago suggested, I added 4 improper interactions to the structure shown in this picture(https://imgur.com/a/JGqMk5l , I was unable to get any confirmation about how many improper interactions I need to add to this structure from the author who writes the paper) in the “replicate” method. However due to my ignorance I originally hadn’t used the appropriate codes to generate the desired improper interactions in the moltemplate method. As this exchange(Improper Dihedrals - #2 by Andrew_Jewett) shows, the first atom type in the moltemplate command “@improper:type1 @atom:typeA @atom:typeB @atom:typeC @atom:typeD”, which is typeA, refers to the so called central atom in the improper interaction, I didn’t know about this rule at first. As a result, certain kinds of improper interactions were not generated at all in my first attempt, which explains the cause of the discrepancy.

After correcting my codes, the number of improper interactions generated by the moltemplate method exceeded the replicate method in my latest attempt. And indeed, it’s a tricky issue to generate the right number of improper interactions in this kind of structure(https://imgur.com/a/JGqMk5l), in this case I need to designate two types of green atoms, green1 and green2 and sort atom types properly in moltemplate command to solve the problem.

As a side note, I found out due to different rules to define the angle between two planes adopted by different improper styles in lammps, one may not produce the final data structure readily used by lammps in one go. For instance, the so called central atom type may appear in the 2nd place in the lammps data structure, so one needs to exchange the 1st and 2nd column of the data generated by moltemplate.