Electronic, Optical, And Magnetic Properties Of Graphene And Single-Layer Transition Metal Dichalcogenides In The Presence Of Defects