Hi, thanks for the question about how the site classes and site sets work.
The shortest answer to your question is that to add new operators, it’s best to create your own new site type, using one of the provided ones as an example. You can copy, say, the boson.h file and just change the name of the class from BosonSite to CustomBosonSite say. Then add new operators and define your own new site set type at the top of the file.
The longer answer, regarding subclassing and reusing existing code, is that you technically can subclass these site classes, but that’s not how they’re intended to be used or extended. (In general C++ doesn’t have a great mechanism for extending things. Each one, such as inheritance, which seems promising at first ends up causing a ton of headaches when you really start using it more seriously.)
But a good approach for what you want to do would be to make a new class CustomBosonSite which just holds a BosonSite inside it (composition). Calling CustomBosonSite’s index() method is then defined as just calling .index() on the BosonSite object held inside of it. For the op(...) method, you would check if the name is one of the new ones you want to define and construct and return the desired operator. Otherwise, you would just call .op(...) on the BosonSite object internally as a fallback method. This way you could save yourself from having to copy-paste all of BosonSites internals into your class.
For some more background on how these site objects work, when they go into a site set object (such as BasicSiteSet) the site set holds a set of opaque “box” types (this is called type erasure) which can hold any one of the site types. This is so that different site types can be mixed and matched within a site set (e.g. S=1 sites throughout the bulk with S=1/2 sites at the edges).
When you call op(sites,”Name”,j) on some site set object “sites”, what it does is call the .op(“Name”,j) method on the site object held in “box” number j. This site object then runs its own op method which creates and returns an ITensor. The site set then returns this ITensor.
Hope that gives you the information you need. Please post another question below if you have a follow up.
Finally, in the new Julia version of ITensor we are almost done with, we are able to take great advantage of the dynamic and language reflection capabilities to make this all much more flexible and extensible with a minimum of code. So please look forward to that!